ScrollEventHandler 代理人
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
表示處理 Scroll
或 ScrollBar 事件 DataGridView 的方法。
public delegate void ScrollEventHandler(System::Object ^ sender, ScrollEventArgs ^ e);
public delegate void ScrollEventHandler(object sender, ScrollEventArgs e);
public delegate void ScrollEventHandler(object? sender, ScrollEventArgs e);
type ScrollEventHandler = delegate of obj * ScrollEventArgs -> unit
Public Delegate Sub ScrollEventHandler(sender As Object, e As ScrollEventArgs)
參數
- sender
- Object
事件的來源。
ScrollEventArgs,其中包含事件資料。
範例
下列程式碼範例示範此類型的用法。
void AddMyScrollEventHandlers()
{
// Create and initialize a VScrollBar.
VScrollBar^ vScrollBar1 = gcnew VScrollBar;
// Add event handlers for the OnScroll and OnValueChanged events.
vScrollBar1->Scroll += gcnew ScrollEventHandler( this, &Form1::vScrollBar1_Scroll );
vScrollBar1->ValueChanged += gcnew 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( "vScrollBar Value:(OnValueChanged Event) {0}", 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( "VScrollBar Value:(OnScroll Event) {0}", 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;
}
}
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;
}
}
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
備註
建立 ScrollEventArgs 委派時,必須識別處理事件的方法。 若要使事件與您的事件處理常式產生關聯,請將委派的執行個體 (Instance) 加入至事件。 除非您移除委派,否則每當事件發生時就會呼叫事件處理常式。 如需事件處理常式委派的詳細資訊,請參閱 處理和引發事件。
擴充方法
GetMethodInfo(Delegate) |
取得表示特定委派所代表之方法的物件。 |