ProgressBar 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
表示 Windows 進度列 (Progress Bar) 控制項。
public ref class ProgressBar sealed : System::Windows::Forms::Control
public ref class ProgressBar : System::Windows::Forms::Control
public sealed class ProgressBar : System.Windows.Forms.Control
[System.ComponentModel.DefaultBindingProperty("Value")]
[System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch)]
[System.Runtime.InteropServices.ComVisible(true)]
public class ProgressBar : System.Windows.Forms.Control
[System.ComponentModel.DefaultBindingProperty("Value")]
public class ProgressBar : System.Windows.Forms.Control
type ProgressBar = class
inherit Control
[<System.ComponentModel.DefaultBindingProperty("Value")>]
[<System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch)>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type ProgressBar = class
inherit Control
[<System.ComponentModel.DefaultBindingProperty("Value")>]
type ProgressBar = class
inherit Control
Public NotInheritable Class ProgressBar
Inherits Control
Public Class ProgressBar
Inherits Control
- 繼承
- 屬性
範例
下列程式碼範例會使用 ProgressBar 控制項來顯示檔案複製作業的進度。 此範例會使用 Minimum 和 Maximum 屬性來指定 ProgressBar 的範圍,其相當於要複製的檔案數目。 程式碼也會使用 Step 屬性搭配 PerformStep 方法,以複製檔案時遞增 的值 ProgressBar 。 此範例會要求您建立 ProgressBar 名為 pBar1
的控制項,該控制項會在 內 Form 建立,而且有一個稱為 CopyFile
(的方法,其會傳回布林值,指出檔案複製作業已順利完成,) 執行檔案複製作業。 程式碼也需要建立包含要複製之檔案的字串陣列,並傳遞至 CopyWithProgress
範例中定義的方法,而且方法是從 中的 Form 另一個方法或事件呼叫。
private:
void CopyWithProgress( array<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();
}
}
}
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();
}
}
}
Private Sub CopyWithProgress(ByVal ParamArray filenames As String())
' 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.
Dim x As Integer
for x = 1 To filenames.Length - 1
' Copy the file and increment the ProgressBar if successful.
If CopyFile(filenames(x - 1)) = True Then
' Perform the increment on the ProgressBar.
pBar1.PerformStep()
End If
Next x
End Sub
備註
ProgressBar控制項會以視覺化方式指出三種樣式之一的冗長作業進度:
從左至右增加步驟的分段區塊。
從左至右填入的連續列。
以 marquee 方式捲動到 ProgressBar 的區塊。
屬性 Style 會決定顯示的 樣式 ProgressBar 。 請注意, ProgressBar 控制項只能水準方向。 如需如何建立垂直導向 ProgressBar 的範例,請參閱 ProgressBarRenderer 類別。 ProgressBar當應用程式執行複製檔案或列印檔案等工作時,通常會使用控制項。 如果沒有視覺提示,應用程式的使用者可能會考慮應用程式沒有回應。 藉由在應用程式中使用 ProgressBar ,您可以警示使用者應用程式正在執行冗長的工作,且應用程式仍會回應。
Maximum和 Minimum 屬性會定義值範圍,以代表工作的進度。 屬性 Minimum 通常會設定為 0 的值,而 Maximum 屬性通常會設定為值,指出工作完成。 例如,若要在複製檔案群組時正確顯示進度, Maximum 可以將 屬性設定為要複製的檔案總數。
屬性 Value 代表應用程式完成作業的進度。 唯一近似 ProgressBar 屬性目前值所顯示的值 Value 。 根據 的大小 ProgressBar , Value 屬性會決定何時要顯示下一個區塊或增加長條的大小。
除了直接變更 Value 屬性以外,還有幾種方式可以修改 所顯示 ProgressBar 的值。 您可以使用 Step 屬性來指定要遞增屬性的特定值,然後呼叫 PerformStep 方法來遞增 Value 值。 若要改變遞增值,您可以使用 Increment 方法,並指定要遞增 Value 屬性的值。
注意
ForeColor 在 Windows XP Home Edition、Windows XP Professional、Windows Server 2003 和更新版本上啟用視覺樣式時,將不會接受 的 和 BackColor 變更 ProgressBar 。
建構函式
ProgressBar() |
初始化 ProgressBar 類別的新執行個體。 |
屬性
AccessibilityObject |
取得指定給控制項的 AccessibleObject。 (繼承來源 Control) |
AccessibleDefaultActionDescription |
取得或設定協助用戶端應用程式所使用的控制項的預設動作描述。 (繼承來源 Control) |
AccessibleDescription |
取得或設定協助工具用戶端應用程式使用之控制項的描述。 (繼承來源 Control) |
AccessibleName |
取得或設定協助工具用戶端應用程式使用的控制項名稱。 (繼承來源 Control) |
AccessibleRole |
取得或設定控制項的可存取角色。 (繼承來源 Control) |
AllowDrop |
取得或設定值,指出控制項是否能接受使用者拖放上來的資料。 |
Anchor |
取得或設定控制項繫結至的容器邊緣,並決定控制項隨其父代重新調整大小的方式。 (繼承來源 Control) |
AutoScrollOffset |
取得或設定此控制項在 ScrollControlIntoView(Control) 中要捲動到哪一個位置。 (繼承來源 Control) |
AutoSize |
這個屬性與這個類別無關。 (繼承來源 Control) |
BackColor |
取得或設定此 ProgressBar 控制項的背景色彩。 |
BackColor |
取得或設定控制項的背景色彩。 (繼承來源 Control) |
BackgroundImage |
取得或設定 ProgressBar 控制項的背景影像。 |
BackgroundImageLayout |
取得或設定進度列的背景影像配置。 |
BackgroundImageLayout |
取得或設定在 ImageLayout 列舉類型中所定義的背景影像配置。 (繼承來源 Control) |
BindingContext |
取得或設定控制項的 BindingContext。 (繼承來源 Control) |
Bottom |
取得控制項下邊緣和其容器工作區 (Client Area) 上邊緣之間的距離 (單位為像素)。 (繼承來源 Control) |
Bounds |
取得或設定控制項 (包括其非工作區項目) 相對於父控制項之大小和位置 (單位為像素)。 (繼承來源 Control) |
CanEnableIme |
取得值,這個值表示 ImeMode 屬性是否可以設定為使用中的值,以啟用 IME 支援。 (繼承來源 Control) |
CanFocus |
取得指示控制項是否能取得焦點的值。 (繼承來源 Control) |
CanRaiseEvents |
判斷是否可以在控制項上引發事件。 (繼承來源 Control) |
CanSelect |
取得指示能否選取控制項的值。 (繼承來源 Control) |
Capture |
取得或設定值,指出控制項是否捕捉住滑鼠。 (繼承來源 Control) |
CausesValidation |
取得或設定值,指出控制項取得焦點時,是否會在任何需要驗證的控制項上執行驗證。 |
ClientRectangle |
取得表示控制項工作區的矩形。 (繼承來源 Control) |
ClientSize |
取得或設定控制項工作區的高度和寬度。 (繼承來源 Control) |
CompanyName |
取得包含控制項之應用程式的公司名稱或建立者。 (繼承來源 Control) |
Container |
取得包含 IContainer 的 Component。 (繼承來源 Component) |
ContainsFocus |
取得指示控制項 (或其子控制項之一) 目前是否擁有輸入焦點的值。 (繼承來源 Control) |
ContextMenu |
取得或設定與控制項關聯的捷徑功能表。 (繼承來源 Control) |
ContextMenuStrip |
取得或設定與這個控制項相關的 ContextMenuStrip。 (繼承來源 Control) |
Controls |
取得控制項中包含的控制項集合。 (繼承來源 Control) |
Created |
取得值,指出是否已經建立控制項。 (繼承來源 Control) |
CreateParams |
覆寫 CreateParams。 |
CreateParams |
建立控制代碼時,取得必要的建立參數。 (繼承來源 Control) |
Cursor |
取得或設定滑鼠指標移至控制項上時顯示的游標。 (繼承來源 Control) |
DataBindings |
取得控制項的資料繫結 (Data Binding)。 (繼承來源 Control) |
DataContext |
取得或設定資料系結用途的資料內容。 這是環境屬性。 (繼承來源 Control) |
DefaultCursor |
取得或設定控制項的預設游標。 (繼承來源 Control) |
DefaultImeMode |
取得控制項支援的預設輸入法 (IME) 模式。 |
DefaultImeMode |
取得控制項支援的預設輸入法 (IME) 模式。 (繼承來源 Control) |
DefaultMargin |
取得控制項之間的預設指定間距 (單位為像素)。 (繼承來源 Control) |
DefaultMaximumSize |
取得指定為控制項的預設大小之最大值的長度和高度 (單位為像素)。 (繼承來源 Control) |
DefaultMinimumSize |
取得指定為控制項的預設大小之最小值的長度和高度 (單位為像素)。 (繼承來源 Control) |
DefaultPadding |
取得控制項內容的內部間距 (單位為像素)。 (繼承來源 Control) |
DefaultSize |
取得控制項的預設大小。 |
DefaultSize |
取得控制項的預設大小。 (繼承來源 Control) |
DesignMode |
取得值,指出 Component 目前是否處於設計模式。 (繼承來源 Component) |
DeviceDpi |
取得目前顯示控制項的顯示裝置的 DPI 值。 (繼承來源 Control) |
DisplayRectangle |
取得表示控制項顯示區域的矩形。 (繼承來源 Control) |
Disposing |
取得值,指出基底 Control 類別是否正在處置的過程中。 (繼承來源 Control) |
Dock |
取得或設定停駐在其父控制項的控制項框線,並決定控制項隨其父代重新調整大小的方式。 (繼承來源 Control) |
DoubleBuffered |
取得或設定值,指出控制項是否應使用次要緩衝區重繪其介面。 |
DoubleBuffered |
取得或設定值,指出這個控制項是否應使用次要緩衝區重繪其介面,以減少或防止重繪閃動 (Flicker)。 (繼承來源 Control) |
Enabled |
取得或設定值,指出控制項是否可回應使用者互動。 (繼承來源 Control) |
Events |
取得附加在這個 Component 上的事件處理常式清單。 (繼承來源 Component) |
Focused |
取得指示控制項是否擁有輸入焦點的值。 (繼承來源 Control) |
Font |
取得或設定 ProgressBar 中文字的字型。 |
FontHeight |
取得或設定控制項字型的高度。 (繼承來源 Control) |
ForeColor |
取得或設定控制項的前景色彩。 |
ForeColor |
取得或設定控制項的前景色彩。 (繼承來源 Control) |
Handle |
取得控制項要繫結的目標視窗控制代碼。 (繼承來源 Control) |
HasChildren |
取得指示控制項是否包含一或多個子控制項的值。 (繼承來源 Control) |
Height |
取得或設定控制項的高度。 (繼承來源 Control) |
ImeMode |
取得或設定 的輸入法編輯器 (輸入法) ProgressBar 。 |
ImeModeBase |
取得或設定控制項的 IME 模式。 (繼承來源 Control) |
InvokeRequired |
取得一個值。這個值會指示是否由於呼叫端是在建立控制項之執行緒以外的執行緒,因此在進行控制項的方法呼叫時,應呼叫叫用 (Invoke) 方法。 (繼承來源 Control) |
IsAccessible |
取得或設定值,指出可及性應用程式是否見得到控制項。 (繼承來源 Control) |
IsAncestorSiteInDesignMode |
指出此控制項的其中一個上階是否已月臺,且該月臺位於 DesignMode 中。 這個屬性是唯讀的。 (繼承來源 Control) |
IsDisposed |
取得指示控制項是否已經處置的值。 (繼承來源 Control) |
IsHandleCreated |
取得指示控制項是否有相關控制代碼的值。 (繼承來源 Control) |
IsMirrored |
取得值,指出是否左右反轉控制項。 (繼承來源 Control) |
LayoutEngine |
取得控制項之配置引擎的快取執行個體。 (繼承來源 Control) |
Left |
取得或設定控制項左邊緣和其容器工作區 (Client Area) 左邊緣之間的距離 (單位為像素)。 (繼承來源 Control) |
Location |
取得或設定對應至控制項容器左上角之控制項左上角的座標。 (繼承來源 Control) |
Margin |
取得或設定控制項之間的空格。 (繼承來源 Control) |
MarqueeAnimationSpeed |
取得或設定進度區塊捲動完整個進度列所需的時間長度 (以毫秒為單位)。 |
Maximum |
取得或設定控制項範圍的最大值。 |
MaximumSize |
取得或設定 GetPreferredSize(Size) 可以指定的上限大小。 (繼承來源 Control) |
Minimum |
取得或設定控制項範圍的最小值。 |
MinimumSize |
取得或設定 GetPreferredSize(Size) 可以指定的下限大小。 (繼承來源 Control) |
Name |
取得或設定控制項的名稱。 (繼承來源 Control) |
Padding |
取得或設定 ProgressBar 控制項的邊緣和其內容之間的間距。 |
Padding |
取得或設定控制項內的邊框間距。 (繼承來源 Control) |
Parent |
取得或設定控制項的父容器。 (繼承來源 Control) |
PreferredSize |
取得能夠容納控制項的矩形區域的大小。 (繼承來源 Control) |
ProductName |
取得包含控制項的組件的產品名稱。 (繼承來源 Control) |
ProductVersion |
取得包含控制項的組件的版本。 (繼承來源 Control) |
RecreatingHandle |
取得指示控制項目前是否正重新建立其控制代碼的值。 (繼承來源 Control) |
Region |
取得或設定與控制項關聯的視窗區域。 (繼承來源 Control) |
RenderRightToLeft |
已淘汰.
已淘汰.
此屬性現在已過時。 (繼承來源 Control) |
ResizeRedraw |
取得或設定值,指出控制項重設大小時,是否會重繪本身。 (繼承來源 Control) |
Right |
取得控制項右邊緣和其容器工作區 (Client Area) 左邊緣之間的距離 (單位為像素)。 (繼承來源 Control) |
RightToLeft |
取得或設定一個值,指出控制項的元素是否對齊以支援使用從右至左字型的地區設定。 |
RightToLeft |
取得或設定值,指出控制項的項目是否對齊,以支援使用由右至左字型的地區設定。 (繼承來源 Control) |
RightToLeftLayout |
取得或設定值,指出 ProgressBar 及其所包含的文字是否由右至左顯示。 |
ScaleChildren |
取得值,以判斷子控制項的縮放。 (繼承來源 Control) |
ShowFocusCues |
取得指示控制項是否應顯示焦點矩形 (Focus Rectangle) 的值。 (繼承來源 Control) |
ShowKeyboardCues |
取得值,指出使用者介面是否處於可顯示或隱藏鍵盤快速鍵的適當狀態下。 (繼承來源 Control) |
Site |
取得或設定控制項的站台。 (繼承來源 Control) |
Size |
取得或設定控制項的高度和寬度。 (繼承來源 Control) |
Step |
取得或設定數量,以其做為呼叫 PerformStep() 方法時對進度列目前位置的增量。 |
Style |
取得或設定在進度列上表示進度所用的方式。 |
TabIndex |
取得或設定控制項容器中的控制項定位順序。 (繼承來源 Control) |
TabStop |
覆寫 TabStop。 |
Tag |
取得或設定物件,其包含控制項相關資料。 (繼承來源 Control) |
Text |
取得或設定這個控制項的相關文字。 |
Top |
取得或設定控制項上邊緣和其容器工作區 (Client Area) 上邊緣之間的距離 (單位為像素)。 (繼承來源 Control) |
TopLevelControl |
取得沒有其他 Windows Form 父控制項的父控制項。 通常,這會是內含控制項最外層的 Form。 (繼承來源 Control) |
UseWaitCursor |
取得或設定值,指出是否將等待游標用於目前控制項和所有子控制項。 (繼承來源 Control) |
Value |
取得或設定進度列的目前位置。 |
Visible |
取得或設定值,這個值指出是否顯示控制項及其所有子控制項。 (繼承來源 Control) |
Width |
取得或設定控制項的寬度。 (繼承來源 Control) |
WindowTarget |
這個屬性與這個類別無關。 (繼承來源 Control) |
方法
事件
明確介面實作
IDropTarget.OnDragDrop(DragEventArgs) |
引發 DragDrop 事件。 (繼承來源 Control) |
IDropTarget.OnDragEnter(DragEventArgs) |
引發 DragEnter 事件。 (繼承來源 Control) |
IDropTarget.OnDragLeave(EventArgs) |
引發 DragLeave 事件。 (繼承來源 Control) |
IDropTarget.OnDragOver(DragEventArgs) |
引發 DragOver 事件。 (繼承來源 Control) |
適用於
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應