ProgressBar 类
ProgressBar?控件以三種樣式中的一種指示較長操作的進度:
-
從左向右分步遞增的分段塊。
-
從左向右填充的連續(xù)欄。
-
以字幕方式在?ProgressBar?中滾動的塊。
Style?屬性確定顯示的?ProgressBar?的樣式。注意,ProgressBar?控件只能是水平方向的。有關(guān)如何創(chuàng)建垂直方向的?ProgressBar?的示例,請參見?ProgressBarRenderer?類。ProgressBar?控件通常在應(yīng)用程序執(zhí)行諸如復(fù)制文件或打印文檔等任務(wù)時使用。如果沒有視覺提示,應(yīng)用程序的用戶可能會認為應(yīng)用程序不響應(yīng)。通過在應(yīng)用程序中使用?ProgressBar,可以警告用戶應(yīng)用程序正在執(zhí)行冗長的任務(wù)且應(yīng)用程序仍在響應(yīng)。
Maximum?和?Minimum?屬性定義了兩個值的范圍用以表現(xiàn)任務(wù)的進度。Minimum?屬性通常設(shè)置為值 0,Maximum?屬性通常設(shè)置為指示任務(wù)完成的值。例如,若要正確顯示復(fù)制一組文件時的進度,Maximum?屬性應(yīng)設(shè)置成要復(fù)制的文件的總數(shù)。
Value?屬性表示應(yīng)用程序在完成操作的過程中的進度。ProgressBar?顯示的值僅僅是近似于?Value?屬性的當(dāng)前值。根據(jù)?ProgressBar?的大小,Value?屬性確定何時顯示下一個塊或增加欄大小。
除了直接更改?Value?屬性之外還有許多方式可以修改由?ProgressBar?顯示的值。可以使用?Step?屬性指定一個特定值用以逐次遞增?Value?屬性的值,然后調(diào)用?PerformStep?方法來使該值遞增。若要更改增量值,可以使用?Increment?方法并指定一個用來遞增?Value?屬性的值。
private void CopyWithProgress(string[] filenames) {// Display the ProgressBar control.pBar1.Visible = true;// Set Minimum to 1 to represent the first file being copied.pBar1.Minimum = 1;// Set Maximum to the total number of files to copy.pBar1.Maximum = filenames.Length;// Set the initial value of the ProgressBar.pBar1.Value = 1;// Set the Step property to a value of 1 to represent each file being copied.pBar1.Step = 1;// Loop through all files to copy.for (int x = 1; x <= filenames.Length; x++){// Copy the file and increment the ProgressBar if successful.if(CopyFile(filenames[x-1]) == true){// Perform the increment on the ProgressBar.pBar1.PerformStep();}} }轉(zhuǎn)載于:https://www.cnblogs.com/wpf123/archive/2011/09/08/2171259.html
總結(jié)
以上是生活随笔為你收集整理的ProgressBar 类的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Hadoop作业提交分析(三)
- 下一篇: WPF,Silverlight与XAML