다음을 통해 공유


TrackBar.ValueChanged 이벤트

트랙 표시줄의 Value 속성이 스크롤 상자 이동이나 코드 조작을 통해 변경될 때 발생합니다.

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

구문

‘선언
Public Event ValueChanged As EventHandler
‘사용 방법
Dim instance As TrackBar
Dim handler As EventHandler

AddHandler instance.ValueChanged, handler
public event EventHandler ValueChanged
public:
event EventHandler^ ValueChanged {
    void add (EventHandler^ value);
    void remove (EventHandler^ value);
}
/** @event */
public void add_ValueChanged (EventHandler value)

/** @event */
public void remove_ValueChanged (EventHandler value)
JScript에서는 이벤트를 사용할 수 있지만 새로 선언할 수는 없습니다.

설명

이 이벤트를 사용하면 트랙 표시줄에 표시된 값이 변경될 때 다른 컨트롤을 업데이트할 수 있습니다.

이벤트 처리에 대한 자세한 내용은 이벤트 사용을 참조하십시오.

예제

다음 코드 예제에서는 TickStyle, MinimumMaximum 멤버를 사용하는 방법과 ValueChanged 이벤트를 처리하는 방법을 보여 줍니다. 이 예제를 실행하려면 TrackBar1이라는 이름의 TrackBar 컨트롤과 TextBox1이라는 이름의 TextBox 컨트롤이 들어 있는 폼에 다음 코드를 붙여 넣습니다. 폼의 생성자나 Load 이벤트 처리 메서드에서 InitializeTrackBar 메서드를 호출합니다.

'Declare a new TrackBar object.
Friend WithEvents TrackBar1 As System.Windows.Forms.TrackBar

' Initalize the TrackBar and add it to the form.
Private Sub InitializeTrackBar()
    Me.TrackBar1 = New System.Windows.Forms.TrackBar

    ' Set the TickStyle property so there are ticks on both sides
    ' of the TrackBar.
    TrackBar1.TickStyle = TickStyle.Both

    ' Set the minimum and maximum number of ticks.
    TrackBar1.Minimum = 10
    TrackBar1.Maximum = 100

    ' Set the tick frequency to one tick every ten units.
    TrackBar1.TickFrequency = 10

    TrackBar1.Location = New System.Drawing.Point(75, 30)
    Me.Controls.Add(Me.TrackBar1)
End Sub


' Handle the TrackBar.ValueChanged event by calculating a value for
' TextBox1 based on the TrackBar value.  
Private Sub TrackBar1_ValueChanged(ByVal sender As Object, _
    ByVal e As System.EventArgs) Handles TrackBar1.ValueChanged
    TextBox1.Text = System.Math.Round(TrackBar1.Value / 10)
End Sub
//Declare a new TrackBar object.
internal System.Windows.Forms.TrackBar TrackBar1;

// Initalize the TrackBar and add it to the form.
private void InitializeTrackBar()
{
    this.TrackBar1 = new System.Windows.Forms.TrackBar();
    TrackBar1.Location = new System.Drawing.Point(75, 30);

    // Set the TickStyle property so there are ticks on both sides
    // of the TrackBar.
    TrackBar1.TickStyle = TickStyle.Both;

    // Set the minimum and maximum number of ticks.
    TrackBar1.Minimum = 10;
    TrackBar1.Maximum = 100;

    // Set the tick frequency to one tick every ten units.
    TrackBar1.TickFrequency = 10;

    // Associate the event-handling method with the 
    // ValueChanged event.
    TrackBar1.ValueChanged += 
        new System.EventHandler(TrackBar1_ValueChanged);
    this.Controls.Add(this.TrackBar1);
}


// Handle the TrackBar.ValueChanged event by calculating a value for
// TextBox1 based on the TrackBar value.  
private void TrackBar1_ValueChanged(object sender, System.EventArgs e)
{
    TextBox1.Text = (System.Math.Round(TrackBar1.Value/10.0)).ToString();
}
   //Declare a new TrackBar object.
internal:
   System::Windows::Forms::TrackBar^ TrackBar1;

   // Initalize the TrackBar and add it to the form.
private:
   void InitializeTrackBar()
   {
      this->TrackBar1 = gcnew System::Windows::Forms::TrackBar;
      TrackBar1->Location = System::Drawing::Point( 75, 30 );
      
      // Set the TickStyle property so there are ticks on both sides
      // of the TrackBar.
      TrackBar1->TickStyle = TickStyle::Both;
      
      // Set the minimum and maximum number of ticks.
      TrackBar1->Minimum = 10;
      TrackBar1->Maximum = 100;
      
      // Set the tick frequency to one tick every ten units.
      TrackBar1->TickFrequency = 10;
      
      // Associate the event-handling method with the 
      // ValueChanged event.
      TrackBar1->ValueChanged += gcnew System::EventHandler( this, &Form1::TrackBar1_ValueChanged );
      this->Controls->Add( this->TrackBar1 );
   }

   // Handle the TrackBar.ValueChanged event by calculating a value for
   // TextBox1 based on the TrackBar value.  
   void TrackBar1_ValueChanged( Object^ /*sender*/, System::EventArgs^ /*e*/ )
   {
      TextBox1->Text = (System::Math::Round( TrackBar1->Value / 10.0 )).ToString();
   }
//Declare a new TrackBar object.
System.Windows.Forms.TrackBar trackBar1;

// Initalize the TrackBar and add it to the form.
private void InitializeTrackBar()
{
    this.trackBar1 = new System.Windows.Forms.TrackBar();
    trackBar1.set_Location(new System.Drawing.Point(75, 30));
    // Set the TickStyle property so there are ticks on both sides
    // of the TrackBar.
    trackBar1.set_TickStyle(TickStyle.Both);
    // Set the minimum and maximum number of ticks.
    trackBar1.set_Minimum(10);
    trackBar1.set_Maximum(100);
    // Set the tick frequency to one tick every ten units.
    trackBar1.set_TickFrequency(10);
    // Associate the event-handling method with the 
    // ValueChanged event.
    trackBar1.add_ValueChanged(new System.EventHandler(
        trackBar1_ValueChanged));
    this.get_Controls().Add(this.trackBar1);
} //InitializeTrackBar

// Handle the TrackBar.ValueChanged event by calculating a value for
// textBox1 based on the TrackBar value.  
private void trackBar1_ValueChanged(Object sender, System.EventArgs e)
{
    textBox1.set_Text(((System.Double)System.Math.Round(
        trackBar1.get_Value() / 10.0)).ToString());
} //trackBar1_ValueChanged

플랫폼

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 클래스
TrackBar 멤버
System.Windows.Forms 네임스페이스