TrackBar 类 
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
表示一个标准的 Windows 跟踪条。
public ref class TrackBar : System::Windows::Forms::Control, System::ComponentModel::ISupportInitialize
	public class TrackBar : System.Windows.Forms.Control, System.ComponentModel.ISupportInitialize
	[System.ComponentModel.DefaultBindingProperty("Value")]
[System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch)]
[System.Runtime.InteropServices.ComVisible(true)]
public class TrackBar : System.Windows.Forms.Control, System.ComponentModel.ISupportInitialize
	[System.ComponentModel.DefaultBindingProperty("Value")]
public class TrackBar : System.Windows.Forms.Control, System.ComponentModel.ISupportInitialize
	type TrackBar = class
    inherit Control
    interface ISupportInitialize
	[<System.ComponentModel.DefaultBindingProperty("Value")>]
[<System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch)>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type TrackBar = class
    inherit Control
    interface ISupportInitialize
	[<System.ComponentModel.DefaultBindingProperty("Value")>]
type TrackBar = class
    inherit Control
    interface ISupportInitialize
	Public Class TrackBar
Inherits Control
Implements ISupportInitialize
		- 继承
 
- 属性
 
- 实现
 
示例
下面的代码示例显示包含 TrackBar 控件和控件的 TextBox 窗体。 该示例演示如何设置 Maximum、 TickFrequency、 LargeChange和 SmallChange 属性以及处理 Scroll 事件。 TextBox事件发生时Scroll,Value内容将更新为属性值。
using namespace System;
using namespace System::Drawing;
using namespace System::Windows::Forms;
public ref class Form1: public System::Windows::Forms::Form
{
private:
   System::Windows::Forms::TrackBar^ trackBar1;
   System::Windows::Forms::TextBox^ textBox1;
public:
   Form1()
   {
      this->textBox1 = gcnew System::Windows::Forms::TextBox;
      this->trackBar1 = gcnew System::Windows::Forms::TrackBar;
      
      // TextBox for TrackBar::Value update.
      this->textBox1->Location = System::Drawing::Point( 240, 16 );
      this->textBox1->Size = System::Drawing::Size( 48, 20 );
      
      // Set up how the form should be displayed and add the controls to the form.
      this->ClientSize = System::Drawing::Size( 296, 62 );
      array<System::Windows::Forms::Control^>^formControls = {this->textBox1,this->trackBar1};
      this->Controls->AddRange( formControls );
      this->Text = "TrackBar Example";
      
      // Set up the TrackBar.
      this->trackBar1->Location = System::Drawing::Point( 8, 8 );
      this->trackBar1->Size = System::Drawing::Size( 224, 45 );
      this->trackBar1->Scroll += gcnew System::EventHandler( this, &Form1::trackBar1_Scroll );
      
      // The Maximum property sets the value of the track bar when
      // the slider is all the way to the right.
      trackBar1->Maximum = 30;
      
      // The TickFrequency property establishes how many positions
      // are between each tick-mark.
      trackBar1->TickFrequency = 5;
      
      // The LargeChange property sets how many positions to move
      // if the bar is clicked on either side of the slider.
      trackBar1->LargeChange = 3;
      
      // The SmallChange property sets how many positions to move
      // if the keyboard arrows are used to move the slider.
      trackBar1->SmallChange = 2;
   }
private:
   void trackBar1_Scroll( Object^ /*sender*/, System::EventArgs^ /*e*/ )
   {
      
      // Display the trackbar value in the text box.
      textBox1->Text = String::Concat( "", trackBar1->Value );
   }
};
[STAThread]
int main()
{
   Application::Run( gcnew Form1 );
}
using System;
using System.Drawing;
using System.Windows.Forms;
public class Form1 : System.Windows.Forms.Form
{
    private System.Windows.Forms.TrackBar trackBar1;
    private System.Windows.Forms.TextBox textBox1;
    [STAThread]
    static void Main() 
    {
        Application.Run(new Form1());
    }
    public Form1()
    {
        this.textBox1 = new System.Windows.Forms.TextBox();
        this.trackBar1 = new System.Windows.Forms.TrackBar();
        // TextBox for TrackBar.Value update.
        this.textBox1.Location = new System.Drawing.Point(240, 16);
        this.textBox1.Size = new System.Drawing.Size(48, 20);
        // Set up how the form should be displayed and add the controls to the form.
        this.ClientSize = new System.Drawing.Size(296, 62);
        this.Controls.AddRange(new System.Windows.Forms.Control[] {this.textBox1,this.trackBar1});
        this.Text = "TrackBar Example";
        // Set up the TrackBar.
        this.trackBar1.Location = new System.Drawing.Point(8, 8);
        this.trackBar1.Size = new System.Drawing.Size(224, 45);
        this.trackBar1.Scroll += new System.EventHandler(this.trackBar1_Scroll);
        // The Maximum property sets the value of the track bar when
        // the slider is all the way to the right.
        trackBar1.Maximum = 30;
        
        // The TickFrequency property establishes how many positions
        // are between each tick-mark.
        trackBar1.TickFrequency = 5;
        // The LargeChange property sets how many positions to move
        // if the bar is clicked on either side of the slider.
        trackBar1.LargeChange = 3;
        // The SmallChange property sets how many positions to move
        // if the keyboard arrows are used to move the slider.
        trackBar1.SmallChange = 2;
    }
    private void trackBar1_Scroll(object sender, System.EventArgs e)
    {
        // Display the trackbar value in the text box.
        textBox1.Text = "" + trackBar1.Value;
    }
}
Imports System.Drawing
Imports System.Windows.Forms
Public Class Form1
    Inherits System.Windows.Forms.Form
    Private WithEvents trackBar1 As System.Windows.Forms.TrackBar
    Private textBox1 As System.Windows.Forms.TextBox
    <System.STAThread()> _
    Public Shared Sub Main()
        System.Windows.Forms.Application.Run(New Form1)
    End Sub
    Public Sub New()
        Me.textBox1 = New System.Windows.Forms.TextBox
        Me.trackBar1 = New System.Windows.Forms.TrackBar
        ' TextBox for TrackBar.Value update.
        Me.textBox1.Location = New System.Drawing.Point(240, 16)
        Me.textBox1.Size = New System.Drawing.Size(48, 20)
        ' Set up how the form should be displayed and add the controls to the form.
        Me.ClientSize = New System.Drawing.Size(296, 62)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.textBox1, Me.trackBar1})
        Me.Text = "TrackBar Example"
        ' Set up the TrackBar.
        Me.trackBar1.Location = New System.Drawing.Point(8, 8)
        Me.trackBar1.Size = New System.Drawing.Size(224, 45)
        ' The Maximum property sets the value of the track bar when
        ' the slider is all the way to the right.
        trackBar1.Maximum = 30
        ' The TickFrequency property establishes how many positions
        ' are between each tick-mark.
        trackBar1.TickFrequency = 5
        ' The LargeChange property sets how many positions to move
        ' if the bar is clicked on either side of the slider.
        trackBar1.LargeChange = 3
        ' The SmallChange property sets how many positions to move
        ' if the keyboard arrows are used to move the slider.
        trackBar1.SmallChange = 2
    End Sub
    Private Sub trackBar1_Scroll(ByVal sender As Object, _
                    ByVal e As System.EventArgs) Handles trackBar1.Scroll
        ' Display the trackbar value in the text box.
        textBox1.Text = trackBar1.Value
    End Sub 
End Class
	注解
TrackBar是类似于 控件ScrollBar的可滚动控件。 可以通过将 属性设置为Minimum指定范围的下端,并将 属性设置为指定范围的Maximum上端,来配置跟踪条的属性值Value滚动到其中的区域。
属性 LargeChange 定义在滚动框任一侧单击时从 Value 属性中添加或减去的增量。 跟踪条可以水平或垂直显示。
可以使用此控件输入通过 Value 属性获取的数值数据。 可以在控件中显示此数值数据,也可以在代码中使用它。
构造函数
| TrackBar() | 
		 初始化 TrackBar 类的新实例。  | 
        	
属性
| AccessibilityObject | 
		 获取分配给该控件的 AccessibleObject。 (继承自 Control) | 
        	
| AccessibleDefaultActionDescription | 
		 获取或设置控件的默认操作说明以供具有辅助功能的客户端应用程序使用。 (继承自 Control) | 
        	
| AccessibleDescription | 
		 获取或设置辅助功能客户端应用程序使用的控件说明。 (继承自 Control) | 
        	
| AccessibleName | 
		 获取或设置辅助功能客户端应用程序所使用的控件名称。 (继承自 Control) | 
        	
| AccessibleRole | 
		 获取或设置控件的辅助性角色。 (继承自 Control) | 
        	
| AllowDrop | 
		 获取或设置一个值,该值指示控件是否可以接受用户拖放到它上面的数据。 (继承自 Control) | 
        	
| Anchor | 
		 获取或设置控件绑定到的容器的边缘并确定控件如何随其父级一起调整大小。 (继承自 Control) | 
        	
| AutoScrollOffset | 
		 获取或设置一个值,该值指示在 ScrollControlIntoView(Control) 中将控件滚动到何处。 (继承自 Control) | 
        	
| AutoSize | 
		 获取或设置一个值,该值指示是否自动调整跟踪条的高度或宽度。  | 
        	
| BackColor | 
		 获取或设置控件的背景色。 (继承自 Control) | 
        	
| BackgroundImage | 
		 获取或设置 TrackBar 控件的背景图像。  | 
        	
| BackgroundImageLayout | 
		 获取或设置一个 ImageLayout 值;但设置此属性对 TrackBar 控件没有影响。  | 
        	
| BackgroundImageLayout | 
		 获取或设置在 ImageLayout 枚举中定义的背景图像布局。 (继承自 Control) | 
        	
| BindingContext | 
		 获取或设置控件的 BindingContext。 (继承自 Control) | 
        	
| Bottom | 
		 获取控件下边缘与其容器的工作区上边缘之间的距离(以像素为单位)。 (继承自 Control) | 
        	
| Bounds | 
		 获取或设置控件(包括其非工作区元素)相对于其父控件的大小和位置(以像素为单位)。 (继承自 Control) | 
        	
| CanEnableIme | 
		 获取一个用以指示是否可以将 ImeMode 属性设置为活动值的值,以启用 IME 支持。 (继承自 Control) | 
        	
| CanFocus | 
		 获取一个值,该值指示控件是否可以接收焦点。 (继承自 Control) | 
        	
| CanRaiseEvents | 
		 确定是否可以在控件上引发事件。 (继承自 Control) | 
        	
| CanSelect | 
		 获取一个值,该值指示是否可以选中控件。 (继承自 Control) | 
        	
| Capture | 
		 获取或设置一个值,该值指示控件是否已捕获鼠标。 (继承自 Control) | 
        	
| CausesValidation | 
		 获取或设置一个值,该值指示控件是否会引起在任何需要在接收焦点时执行验证的控件上执行验证。 (继承自 Control) | 
        	
| ClientRectangle | 
		 获取表示控件的工作区的矩形。 (继承自 Control) | 
        	
| ClientSize | 
		 获取或设置控件的工作区的高度和宽度。 (继承自 Control) | 
        	
| CompanyName | 
		 获取包含控件的应用程序的公司名称或创建者。 (继承自 Control) | 
        	
| Container | 
		 获取包含 IContainer 的 Component。 (继承自 Component) | 
        	
| ContainsFocus | 
		 获取一个值,该值指示控件或它的一个子控件当前是否有输入焦点。 (继承自 Control) | 
        	
| ContextMenu | 
		 获取或设置与控件关联的快捷菜单。 (继承自 Control) | 
        	
| ContextMenuStrip | 
		 获取或设置与此控件关联的 ContextMenuStrip。 (继承自 Control) | 
        	
| Controls | 
		 获取包含在控件内的控件的集合。 (继承自 Control) | 
        	
| Created | 
		 获取一个值,该值指示控件是否已经创建。 (继承自 Control) | 
        	
| CreateParams | 
		 重写 CreateParams 属性。  | 
        	
| Cursor | 
		 获取或设置当鼠标指针位于控件上时显示的光标。 (继承自 Control) | 
        	
| DataBindings | 
		 为该控件获取数据绑定。 (继承自 Control) | 
        	
| DataContext | 
		 获取或设置用于数据绑定的数据上下文。 这是一个环境属性。 (继承自 Control) | 
        	
| DefaultCursor | 
		 获取或设置控件的默认光标。 (继承自 Control) | 
        	
| DefaultImeMode | 
		 获取一个值,该值指示 TrackBar 的输入法编辑器 (IME) 的模式。  | 
        	
| DefaultMargin | 
		 获取控件之间默认指定的间距(以像素为单位)。 (继承自 Control) | 
        	
| DefaultMaximumSize | 
		 获取以像素为单位的长度和高度,此长度和高度被指定为控件的默认最大大小。 (继承自 Control) | 
        	
| DefaultMinimumSize | 
		 获取以像素为单位的长度和高度,此长度和高度被指定为控件的默认最小大小。 (继承自 Control) | 
        	
| DefaultPadding | 
		 获取 控件内容的默认内部间距(以像素为单位)。 (继承自 Control) | 
        	
| DefaultSize | 
		 获取 TrackBar 的默认大小。  | 
        	
| DesignMode | 
		 获取一个值,用以指示 Component 当前是否处于设计模式。 (继承自 Component) | 
        	
| DeviceDpi | 
		 获取显示当前控件的显示设备的 DPI 值。 (继承自 Control) | 
        	
| DisplayRectangle | 
		 获取表示控件的显示区域的矩形。 (继承自 Control) | 
        	
| Disposing | 
		 获取一个值,该值指示 Control 基类是否在释放进程中。 (继承自 Control) | 
        	
| Dock | 
		 获取或设置哪些控件边框停靠到其父控件并确定控件如何随其父级一起调整大小。 (继承自 Control) | 
        	
| DoubleBuffered | 
		 获取或设置一个值,该值指示此控件是否使用次要缓冲区重绘其图面以降低或避免闪烁,但此属性对 TrackBar 控件没有影响。  | 
        	
| DoubleBuffered | 
		 获取或设置一个值,该值指示此控件是否应使用辅助缓冲区重绘其图面,以减少或避免闪烁。 (继承自 Control) | 
        	
| Enabled | 
		 获取或设置一个值,该值指示控件是否可以对用户交互作出响应。 (继承自 Control) | 
        	
| Events | 
		 获取附加到此 Component 的事件处理程序的列表。 (继承自 Component) | 
        	
| Focused | 
		 获取一个值,该值指示控件是否有输入焦点。 (继承自 Control) | 
        	
| Font | 
		 重写 Font。  | 
        	
| FontHeight | 
		 获取或设置控件的字体的高度。 (继承自 Control) | 
        	
| ForeColor | 
		 获取跟踪条的前景色。  | 
        	
| Handle | 
		 获取控件绑定到的窗口句柄。 (继承自 Control) | 
        	
| HasChildren | 
		 获取一个值,该值指示控件是否包含一个或多个子控件。 (继承自 Control) | 
        	
| Height | 
		 获取或设置控件的高度。 (继承自 Control) | 
        	
| ImeMode | 
		 获取或设置此控件所支持的输入法编辑器 (IME) 模式。  | 
        	
| ImeModeBase | 
		 获取或设置控件的 IME 模式。 (继承自 Control) | 
        	
| InvokeRequired | 
		 获取一个值,该值指示调用方在对控件进行方法调用时是否必须调用 Invoke 方法,因为调用方位于创建控件所在的线程以外的线程中。 (继承自 Control) | 
        	
| IsAccessible | 
		 获取或设置一个值,该值指示控件对辅助功能应用程序是否可见。 (继承自 Control) | 
        	
| IsAncestorSiteInDesignMode | 
		 指示此控件的上级之一是否位于 DesignMode 中以及该站点。 此属性为只读。 (继承自 Control) | 
        	
| IsDisposed | 
		 获取一个值,该值指示控件是否已经被释放。 (继承自 Control) | 
        	
| IsHandleCreated | 
		 获取一个值,该值指示控件是否有与它关联的句柄。 (继承自 Control) | 
        	
| IsMirrored | 
		 获取一个值,该值指示此控件是否为镜像控件。 (继承自 Control) | 
        	
| LargeChange | 
		 获取或设置一个值,当滚动框长距离移动时向 Value 属性加上该值或从中减去该值。  | 
        	
| LayoutEngine | 
		 获取控件的布局引擎的缓存实例。 (继承自 Control) | 
        	
| Left | 
		 获取或设置控件左边缘与其容器的工作区左边缘之间的距离(以像素为单位)。 (继承自 Control) | 
        	
| Location | 
		 获取或设置该控件的左上角相对于其容器的左上角的坐标。 (继承自 Control) | 
        	
| Margin | 
		 获取或设置控件之间的空间。 (继承自 Control) | 
        	
| Maximum | 
		 获取或设置此 TrackBar 使用的范围的上限。  | 
        	
| MaximumSize | 
		 获取或设置大小,该大小是 GetPreferredSize(Size) 可以指定的上限。 (继承自 Control) | 
        	
| Minimum | 
		 获取或设置此 TrackBar 使用的范围的下限。  | 
        	
| MinimumSize | 
		 获取或设置大小,该大小是 GetPreferredSize(Size) 可以指定的下限。 (继承自 Control) | 
        	
| Name | 
		 获取或设置控件的名称。 (继承自 Control) | 
        	
| Orientation | 
		 获取或设置一个值,该值指示跟踪条在水平方向还是在垂直方向。  | 
        	
| Padding | 
		 获取或设置 TrackBar 控件的边缘及其内容之间的间距。  | 
        	
| Padding | 
		 获取或设置控件内的空白。 (继承自 Control) | 
        	
| Parent | 
		 获取或设置控件的父容器。 (继承自 Control) | 
        	
| PreferredSize | 
		 获取可以容纳控件的矩形区域的大小。 (继承自 Control) | 
        	
| ProductName | 
		 获取包含控件的程序集的产品名称。 (继承自 Control) | 
        	
| ProductVersion | 
		 获取包含控件的程序集的版本。 (继承自 Control) | 
        	
| RecreatingHandle | 
		 获取一个值,该值指示控件当前是否在重新创建其句柄。 (继承自 Control) | 
        	
| Region | 
		 获取或设置与控件关联的窗口区域。 (继承自 Control) | 
        	
| RenderRightToLeft | 
			 
		已过时.
	 
	
		已过时.
	 
此属性现已过时。 (继承自 Control) | 
        	
| ResizeRedraw | 
		 获取或设置一个值,该值指示控件在调整大小时是否重绘自己。 (继承自 Control) | 
        	
| Right | 
		 获取控件右边缘与其容器的工作区左边缘之间的距离(以像素为单位)。 (继承自 Control) | 
        	
| RightToLeft | 
		 获取或设置一个值,该值指示是否将控件的元素对齐以支持使用从右向左的字体的区域设置。 (继承自 Control) | 
        	
| RightToLeftLayout | 
		 获取或设置一个值,该值指示 TrackBar 的内容是否将从右向左布局。  | 
        	
| ScaleChildren | 
		 获取一个值,该值确定子控件的缩放。 (继承自 Control) | 
        	
| ShowFocusCues | 
		 获取一个值,该值指示控件是否应显示聚焦框。 (继承自 Control) | 
        	
| ShowKeyboardCues | 
		 获取一个值,该值指示用户界面是否处于适当的状态以显示或隐藏键盘快捷键。 (继承自 Control) | 
        	
| Site | 
		 获取或设置控件的站点。 (继承自 Control) | 
        	
| Size | 
		 获取或设置控件的高度和宽度。 (继承自 Control) | 
        	
| SmallChange | 
		 获取或设置当滚动框短距离移动时对 Value 属性进行增减的值。  | 
        	
| TabIndex | 
		 获取或设置控件在其容器内的 Tab 键顺序。 (继承自 Control) | 
        	
| TabStop | 
		 获取或设置一个值,该值指示用户能否使用 Tab 键将焦点放到该控件上。 (继承自 Control) | 
        	
| Tag | 
		 获取或设置包含有关控件的数据的对象。 (继承自 Control) | 
        	
| Text | 
		 获取或设置 TrackBar 的文本。  | 
        	
| TickFrequency | 
		 获取或设置一个值,该值指定控件上绘制的刻度之间的增量。  | 
        	
| TickStyle | 
		 获取或设置一个值,该值指示如何显示跟踪条上的刻度线。  | 
        	
| 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) |