ProgressBar 类
ProgressBar?控件以三種樣式中的一種指示較長操作的進度:
-
從左向右分步遞增的分段塊。
-
從左向右填充的連續欄。
-
以字幕方式在?ProgressBar?中滾動的塊。
Style?屬性確定顯示的?ProgressBar?的樣式。注意,ProgressBar?控件只能是水平方向的。有關如何創建垂直方向的?ProgressBar?的示例,請參見?ProgressBarRenderer?類。ProgressBar?控件通常在應用程序執行諸如復制文件或打印文檔等任務時使用。如果沒有視覺提示,應用程序的用戶可能會認為應用程序不響應。通過在應用程序中使用?ProgressBar,可以警告用戶應用程序正在執行冗長的任務且應用程序仍在響應。
Maximum?和?Minimum?屬性定義了兩個值的范圍用以表現任務的進度。Minimum?屬性通常設置為值 0,Maximum?屬性通常設置為指示任務完成的值。例如,若要正確顯示復制一組文件時的進度,Maximum?屬性應設置成要復制的文件的總數。
Value?屬性表示應用程序在完成操作的過程中的進度。ProgressBar?顯示的值僅僅是近似于?Value?屬性的當前值。根據?ProgressBar?的大小,Value?屬性確定何時顯示下一個塊或增加欄大小。
除了直接更改?Value?屬性之外還有許多方式可以修改由?ProgressBar?顯示的值。可以使用?Step?屬性指定一個特定值用以逐次遞增?Value?屬性的值,然后調用?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();}} }轉載于:https://www.cnblogs.com/wpf123/archive/2011/09/08/2171259.html
總結
以上是生活随笔為你收集整理的ProgressBar 类的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Hadoop作业提交分析(三)
- 下一篇: 结构化程序设计03 - 零基础入门学习D