TrackBar.ValueChanged 이벤트

정의

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

public:
 event EventHandler ^ ValueChanged;
public event EventHandler ValueChanged;
public event EventHandler? ValueChanged;
member this.ValueChanged : EventHandler 
Public Custom Event ValueChanged As EventHandler 

이벤트 유형

예제

다음 코드 예제를 사용 TickStyle하는 방법에 설명 합니다 , Minimum, 및 멤버 및 Maximum 이벤트를 처리 ValueChanged 하는 방법. 예제를 실행하려면 다음 코드를 컨트롤 이름과 TrackBar1 라는 TextBox1컨트롤이 포함된 TrackBar 양식에 TextBox 붙여넣습니다. 폼의 InitializeTrackBar 생성자 또는 Load 이벤트 처리 메서드에서 메서드를 호출합니다.

   //Declare a new TrackBar object.
internal:
   System::Windows::Forms::TrackBar^ TrackBar1;

   // Initialize 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.
internal System.Windows.Forms.TrackBar TrackBar1;

// Initialize 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.
Friend WithEvents TrackBar1 As System.Windows.Forms.TrackBar

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

설명

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

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

적용 대상