다음을 통해 공유


TrackBar 클래스

표준 Windows 트랙 표시줄을 나타냅니다.

네임스페이스: System.Windows.Forms
어셈블리: System.Windows.Forms(system.windows.forms.dll)

구문

‘선언
<ComVisibleAttribute(True)> _
<ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)> _
Public Class TrackBar
    Inherits Control
    Implements ISupportInitialize
‘사용 방법
Dim instance As TrackBar
[ComVisibleAttribute(true)] 
[ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)] 
public class TrackBar : Control, ISupportInitialize
[ComVisibleAttribute(true)] 
[ClassInterfaceAttribute(ClassInterfaceType::AutoDispatch)] 
public ref class TrackBar : public Control, ISupportInitialize
/** @attribute ComVisibleAttribute(true) */ 
/** @attribute ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch) */ 
public class TrackBar extends Control implements ISupportInitialize
ComVisibleAttribute(true) 
ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch) 
public class TrackBar extends Control implements ISupportInitialize

설명

TrackBarScrollBar 컨트롤과 유사하며 스크롤할 수 있는 컨트롤입니다. Minimum 속성을 설정해서 범위의 하한을 지정하고 Maximum 속성을 설정해서 범위의 상한을 지정하여 트랙 표시줄의 Value 속성 값이 스크롤하는 범위를 구성할 수 있습니다.

LargeChange 속성은 스크롤 상자의 어느 한 쪽을 클릭할 때 Value 속성에서 증가되거나 감소되는 값을 정의합니다. 트랙 표시줄은 가로나 세로로 표시될 수 있습니다.

이 컨트롤을 사용하면 Value 속성을 통해 가져온 수치 데이터를 입력할 수 있습니다. 입력한 수치 데이터를 컨트롤에 표시하거나 코드에서 사용할 수 있습니다.

예제

다음 코드 예제에서는 TrackBar 컨트롤 및 TextBox 컨트롤이 들어 있는 폼을 표시합니다. 다음 예제에서는 Maximum, TickFrequency, LargeChangeSmallChange 속성을 설정하고 Scroll 이벤트를 설정하는 방법을 보여 줍니다. Scroll 이벤트가 발생할 때 TextBox 내용이 Value 속성 값으로 업데이트됩니다.

Imports System
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 'Main

    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 'New

    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 '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;
    }
}
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 );
}
import System.*;
import System.Drawing.*;
import System.Windows.Forms.*;

public class Form1 extends System.Windows.Forms.Form
{
    private System.Windows.Forms.TrackBar trackBar1;
    private System.Windows.Forms.TextBox textBox1;

    /** @attribute STAThread()
     */
    public static void main(String[] args)
    {
        Application.Run(new Form1());
    } //main

    public Form1()
    {
        this.textBox1 = new System.Windows.Forms.TextBox();
        this.trackBar1 = new System.Windows.Forms.TrackBar();
        // TextBox for TrackBar.Value update.
        this.textBox1.set_Location(new System.Drawing.Point(240, 16));
        this.textBox1.set_Size(new System.Drawing.Size(48, 20));
        // Set up how the form should be displayed and add the controls to the
        // form.
        this.set_ClientSize(new System.Drawing.Size(296, 62));
        this.get_Controls().AddRange(new System.Windows.Forms.Control[] { 
            this.textBox1, this.trackBar1 });
        this.set_Text("TrackBar Example");
        // Set up the TrackBar.
        this.trackBar1.set_Location(new System.Drawing.Point(8, 8));
        this.trackBar1.set_Size(new System.Drawing.Size(224, 45));
        this.trackBar1.add_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.set_Maximum(30);
        // The TickFrequency property establishes how many positions
        // are between each tick-mark.
        trackBar1.set_TickFrequency(5);
        // The LargeChange property sets how many positions to move
        // if the bar is clicked on either side of the slider.
        trackBar1.set_LargeChange(3);
        // The SmallChange property sets how many positions to move
        // if the keyboard arrows are used to move the slider.
        trackBar1.set_SmallChange(2);
    } //Form1

    private void trackBar1_Scroll(Object sender, System.EventArgs e)
    {
        // Display the trackbar value in the text box.
        textBox1.set_Text("" + trackBar1.get_Value());
    } //trackBar1_Scroll
} //Form1

상속 계층 구조

System.Object
   System.MarshalByRefObject
     System.ComponentModel.Component
       System.Windows.Forms.Control
        System.Windows.Forms.TrackBar

스레드로부터의 안전성

이 형식의 모든 public static(Visual Basic의 경우 Shared) 멤버는 스레드로부터 안전합니다. 인터페이스 멤버는 스레드로부터 안전하지 않습니다.

플랫폼

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework에서 모든 플래폼의 모든 버전을 지원하지는 않습니다. 지원되는 버전의 목록은 시스템 요구 사항을 참조하십시오.

버전 정보

.NET Framework

2.0, 1.1, 1.0에서 지원

.NET Compact Framework

2.0, 1.0에서 지원

참고 항목

참조

TrackBar 멤버
System.Windows.Forms 네임스페이스