スライダの移動またはコードによる操作によって、トラック バーの Value プロパティが変更されると発生します。
Public Event ValueChanged As EventHandler
[C#]
public event EventHandler ValueChanged;
[C++]
public: __event EventHandler* ValueChanged;
[JScript] JScript では、このクラスで定義されているイベントを処理できます。ただし、独自に定義することはできません。
イベント データ
イベント ハンドラが EventArgs 型の引数を受け取りました。
解説
このイベントを使用すると、トラック バーに表されている値が変更される場合に、その他のコントロールを更新できます。
TrackBar デリゲートを作成する場合は、イベントを処理するメソッドを識別してください。イベントをイベント ハンドラに関連付けるには、デリゲートのインスタンスをイベントに追加します。デリゲートを削除しない限り、そのイベントが発生すると常にイベント ハンドラが呼び出されます。
イベント ハンドラ デリゲートの詳細については、「 イベントとデリゲート 」を参照してください。
イベント処理の詳細については、「 イベントの利用 」を参照してください。
使用例
[Visual Basic, C#] TickFrequency 、 Minimum 、 Maximum の各メンバの使用方法、および ValueChanged イベントの処理方法を示すコード例を次に示します。この例を実行するには、TrackBar1 という名前の TrackBar コントロールと TextBox1 という名前の RichTextBox コントロールが配置されているフォームに、次のコードを配置します。そして、フォームのコンストラクタまたは 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
[C#]
//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();
}
[C++, JScript] C++ および JScript のサンプルはありません。Visual Basic および C# のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
必要条件
プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ