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 

イベントの種類

次のコード例では、および メンバーをTickStyleMinimum使用する方法とMaximum、イベントを処理する方法をValueChanged示します。 この例を実行するには、次のコードを、コントロール名と という名前TrackBar1TextBox1のコントロールを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

注釈

このイベントを使用すると、トラック バーで表される値が変更されたときに他のコントロールを更新できます。

イベントの処理の詳細については、「処理とイベントの発生」を参照してください。

適用対象