ProgressBar 类
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
表示 Windows 进度栏控件。
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 。 此示例要求你有一个在一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 ] ))
{
// 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]))
{
// 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 直观地以三种样式之一指示冗长操作的进度:
从左到右增加步骤的分段块。
从左到右填充的连续条。
以选框方式滚动 ProgressBar 的块。
该 Style 属性确定显示的 ProgressBar 样式。 请注意, ProgressBar 控件只能水平方向。 有关如何创建垂直方向 ProgressBar的示例,请参阅该 ProgressBarRenderer 类。 当 ProgressBar 应用程序执行复制文件或打印文档等任务时,通常会使用该控件。 如果没有视觉提示,应用程序的用户可能会认为应用程序无响应。 通过使用应用程序中, ProgressBar 可以通知用户应用程序正在执行较长的任务,并且应用程序仍在响应。
属性MaximumMinimum定义表示任务的进度的值范围。 该 Minimum 属性通常设置为 0 值, Maximum 并且该属性通常设置为指示任务完成的值。 例如,若要在复制一组文件时正确显示进度, Maximum 可将该属性设置为要复制的文件总数。
该 Value 属性表示应用程序完成操作的进度。 唯一 ProgressBar 近似属性的 Value 当前值所显示的值。 根据大小 ProgressBar, Value 属性确定何时显示下一个块或增加条形图的大小。
除了直接更改Value属性之外,还有多种方式可以修改由其他方法显示ProgressBar的值。 可以使用该 Step 属性指定要递增 Value 属性的特定值,然后调用 PerformStep 该方法来递增该值。 若要改变增量值,可以使用 Increment 该方法并指定要递增 Value 属性的值。
注释
ForeColor BackColor ProgressBar在 Windows XP Home Edition、Windows XP Professional、Windows Server 2003 及更高版本上启用视觉样式时,将不遵循这些更改。
构造函数
| 名称 | 说明 |
|---|---|
| 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 |
获取或设置进度栏的背景图像的布局。 |
| BindingContext |
获取或设置 BindingContext 控件。 (继承自 Control) |
| Bottom |
获取控件的下边缘与其容器工作区的上边缘之间的距离(以像素为单位)。 (继承自 Control) |
| Bounds |
获取或设置控件的大小和位置,包括其相对于父控件的非client 元素(以像素为单位)。 (继承自 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 |
获取控件的数据绑定。 (继承自 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 |
获取或设置一个值,该值指示控件是否应使用辅助缓冲区重新绘制其图面。 |
| Enabled |
获取或设置一个值,该值指示控件是否可以响应用户交互。 (继承自 Control) |
| Events |
获取附加到此 Component对象的事件处理程序的列表。 (继承自 Component) |
| Focused |
获取一个值,该值指示控件是否具有输入焦点。 (继承自 Control) |
| Font |
获取或设置 . 中的 ProgressBar文本字体。 |
| FontHeight |
获取或设置控件字体的高度。 (继承自 Control) |
| ForeColor |
获取或设置控件的前景色。 |
| ForeColor |
获取或设置控件的前景色。 (继承自 Control) |
| Handle |
获取控件绑定到的窗口句柄。 (继承自 Control) |
| HasChildren |
获取一个值,该值指示控件是否包含一个或多个子控件。 (继承自 Control) |
| Height |
获取或设置控件的高度。 (继承自 Control) |
| ImeMode |
获取或设置 .. 的 ProgressBar输入法编辑器 (IME) |
| ImeModeBase |
获取或设置控件的 IME 模式。 (继承自 Control) |
| InvokeRequired |
获取一个值,该值指示调用方在对控件进行方法调用时是否必须调用调用方法,因为调用方与创建控件的线程不同。 (继承自 Control) |
| IsAccessible |
获取或设置一个值,该值指示控件是否对辅助功能应用程序可见。 (继承自 Control) |
| IsAncestorSiteInDesignMode |
指示此控件的上级位置之一是否位于 DesignMode 中。 此属性为只读。 (继承自 Control) |
| IsDisposed |
获取一个值,该值指示控件是否已释放。 (继承自 Control) |
| IsHandleCreated |
获取一个值,该值指示控件是否具有与之关联的句柄。 (继承自 Control) |
| IsMirrored |
获取一个值,该值指示控件是否镜像。 (继承自 Control) |
| LayoutEngine |
获取控件布局引擎的缓存实例。 (继承自 Control) |
| Left |
获取或设置控件左边缘与其容器工作区的左边缘之间的距离(以像素为单位)。 (继承自 Control) |
| Location |
获取或设置控件左上角相对于其容器左上角的坐标。 (继承自 Control) |
| Margin |
获取或设置控件之间的间距。 (继承自 Control) |
| MarqueeAnimationSpeed |
获取或设置进度块在进度条上滚动的时间段(以毫秒为单位)。 |
| Maximum |
获取或设置控件范围的最大值。 |
| MaximumSize |
获取或设置可指定上限 GetPreferredSize(Size) 的大小。 (继承自 Control) |
| Minimum |
获取或设置控件范围的最小值。 |
| MinimumSize |
获取或设置可以指定的下限 GetPreferredSize(Size) 的大小。 (继承自 Control) |
| Name |
获取或设置控件的名称。 (继承自 Control) |
| Padding |
获取或设置控件边缘 ProgressBar 与其内容之间的间距。 |
| Parent |
获取或设置控件的父容器。 (继承自 Control) |
| PreferredSize |
获取控件可以容纳到的矩形区域的大小。 (继承自 Control) |
| ProductName |
获取包含控件的程序集的产品名称。 (继承自 Control) |
| ProductVersion |
获取包含控件的程序集的版本。 (继承自 Control) |
| RecreatingHandle |
获取一个值,该值指示控件当前是否正在重新创建其句柄。 (继承自 Control) |
| Region |
获取或设置与控件关联的窗口区域。 (继承自 Control) |
| RenderRightToLeft |
已过时.
已过时.
此属性现已过时。 (继承自 Control) |
| ResizeRedraw |
获取或设置一个值,该值指示控件在调整大小时是否重新绘制自身。 (继承自 Control) |
| Right |
获取控件右边缘与其容器工作区的左边缘之间的距离(以像素为单位)。 (继承自 Control) |
| RightToLeft |
获取或设置一个值,该值指示控件的元素是否对齐以支持使用从右向左字体的区域设置。 |
| RightToLeft |
获取或设置一个值,该值指示控件的元素是否对齐以支持使用从右到左字体的区域设置。 (继承自 Control) |
| RightToLeftLayout |
获取或设置一个值,该值指示它包含的文本是否 ProgressBar 从右到左显示。 |
| ScaleChildren |
获取一个值,该值确定子控件的缩放。 (继承自 Control) |
| ShowFocusCues |
获取一个值,该值指示控件是否应显示焦点矩形。 (继承自 Control) |
| ShowKeyboardCues |
获取一个值,该值指示用户界面是否处于适当的状态以显示或隐藏键盘加速器。 (继承自 Control) |
| Site |
获取或设置控件的站点。 (继承自 Control) |
| Size |
获取或设置控件的高度和宽度。 (继承自 Control) |
| Step |
获取或设置对方法的调用 PerformStep() 增加进度栏当前位置的量。 |
| Style |
获取或设置应在进度栏上指示进度的方式。 |
| TabIndex |
获取或设置控件在其容器中的 Tab 键顺序。 (继承自 Control) |
| TabStop |
重写 TabStop。 |
| Tag |
获取或设置包含有关控件的数据的对象。 (继承自 Control) |
| Text |
获取或设置与此控件关联的文本。 |
| Top |
获取或设置控件上边缘与其容器工作区上边缘之间的距离(以像素为单位)。 (继承自 Control) |
| TopLevelControl |
获取其他 Windows 窗体控件未父控件的父控件。 通常,这是控件包含在的最外层 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) |