ScrollEventHandler デリゲート
ScrollBar 、 TrackBar 、または DataGrid の Scroll イベントを処理するメソッドを表します。
<Serializable>
Public Delegate Sub ScrollEventHandler( _ ByVal sender As Object, _ ByVal e As ScrollEventArgs _)
[C#]
[Serializable]
public delegate void ScrollEventHandler( object sender, ScrollEventArgs e);
[C++]
[Serializable]
public __gc __delegate void ScrollEventHandler( Object* sender, ScrollEventArgs* e);
[JScript] JScript では、.NET Framework のデリゲートを利用することができます。ただし、独自に定義することはできません。
パラメータ [Visual Basic, C#, C++]
作成するイベント ハンドラは、ScrollEventHandler クラスのデリゲート定義と同一のパラメータを持つ必要があります。
- sender
イベントのソース。 - e
イベント データを格納している ScrollEventArgs 。
解説
ScrollEventArgs デリゲートを作成する場合は、イベントを処理するメソッドを識別します。イベントをイベント ハンドラに関連付けるには、デリゲートのインスタンスをイベントに追加します。デリゲートを削除しない限り、そのイベントが発生すると常にイベント ハンドラが呼び出されます。イベント ハンドラ デリゲートの詳細については、「 イベントとデリゲート 」を参照してください。
使用例
Private Sub AddMyScrollEventHandlers()
' Create and initialize a VScrollBar.
Dim vScrollBar1 As New VScrollBar()
' Add event handlers for the OnScroll and OnValueChanged events.
AddHandler vScrollBar1.Scroll, AddressOf Me.vScrollBar1_Scroll
AddHandler vScrollBar1.ValueChanged, AddressOf Me.vScrollBar1_ValueChanged
End Sub
' Create the ValueChanged event handler.
Private Sub vScrollBar1_ValueChanged(sender As Object, e As EventArgs)
' Display the new value in the label.
label1.Text = "vScrollBar Value:(OnValueChanged Event) " & _
vScrollBar1.Value.ToString()
End Sub
' Create the Scroll event handler.
Private Sub vScrollBar1_Scroll(sender As Object, e As ScrollEventArgs)
' Display the new value in the label.
label1.Text = "VScrollBar Value:(OnScroll Event) " & _
e.NewValue.ToString()
End Sub
Private Sub button1_Click(sender As Object, e As EventArgs)
' Add 40 to the Value property if it will not exceed the Maximum value.
If vScrollBar1.Value + 40 < vScrollBar1.Maximum Then
vScrollBar1.Value = vScrollBar1.Value + 40
End If
End Sub
[C#]
private void AddMyScrollEventHandlers()
{
// Create and initialize a VScrollBar.
VScrollBar vScrollBar1 = new VScrollBar();
// Add event handlers for the OnScroll and OnValueChanged events.
vScrollBar1.Scroll += new ScrollEventHandler(
this.vScrollBar1_Scroll);
vScrollBar1.ValueChanged += new EventHandler(
this.vScrollBar1_ValueChanged);
}
// Create the ValueChanged event handler.
private void vScrollBar1_ValueChanged(Object sender,
EventArgs e)
{
// Display the new value in the label.
label1.Text = "vScrollBar Value:(OnValueChanged Event) " + vScrollBar1.Value.ToString();
}
// Create the Scroll event handler.
private void vScrollBar1_Scroll(Object sender,
ScrollEventArgs e)
{
// Display the new value in the label.
label1.Text = "VScrollBar Value:(OnScroll Event) " + e.NewValue.ToString();
}
private void button1_Click(Object sender,
EventArgs e)
{
// Add 40 to the Value property if it will not exceed the Maximum value.
if (vScrollBar1.Value + 40 < vScrollBar1.Maximum)
{
vScrollBar1.Value = vScrollBar1.Value + 40;
}
}
[C++]
private:
void AddMyScrollEventHandlers()
{
// Create and initialize a VScrollBar.
VScrollBar* vScrollBar1 = new VScrollBar();
// Add event handlers for the OnScroll and OnValueChanged events.
vScrollBar1->Scroll += new ScrollEventHandler(this,
&Form1::vScrollBar1_Scroll);
vScrollBar1->ValueChanged += new EventHandler(this,
&Form1::vScrollBar1_ValueChanged);
}
// Create the ValueChanged event handler.
void vScrollBar1_ValueChanged(Object* /*sender*/,
EventArgs* /*e*/)
{
// Display the new value in the label.
label1->Text = String::Format( S"vScrollBar Value:(OnValueChanged Event) {0}",
__box(vScrollBar1->Value));
}
// Create the Scroll event handler.
void vScrollBar1_Scroll(Object* /*sender*/,
ScrollEventArgs* e)
{
// Display the new value in the label.
label1->Text = String::Format( S"VScrollBar Value:(OnScroll Event) {0}",
__box(e->NewValue));
}
void button1_Click(Object* /*sender*/,
EventArgs* /*e*/)
{
// Add 40 to the Value property if it will not exceed the Maximum value.
if (vScrollBar1->Value + 40 < vScrollBar1->Maximum)
{
vScrollBar1->Value = vScrollBar1->Value + 40;
}
}
[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
必要条件
名前空間: System.Windows.Forms
プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ
アセンブリ: System.Windows.Forms (System.Windows.Forms.dll 内)