共用方式為


ScrollableControl.Scroll 事件

定義

當使用者或程式碼在客戶端區域滾動時會發生。

public:
 event System::Windows::Forms::ScrollEventHandler ^ Scroll;
public event System.Windows.Forms.ScrollEventHandler Scroll;
public event System.Windows.Forms.ScrollEventHandler? Scroll;
member this.Scroll : System.Windows.Forms.ScrollEventHandler 
Public Custom Event Scroll As ScrollEventHandler 

事件類型

範例

以下程式碼範例展示了此成員的使用方式。 在這個例子中,事件處理者會回報事件 Scroll 的發生情況。 此報告能幫助您了解事件發生時間,並協助除錯。 若要報告多個事件或頻繁發生的事件,請考慮將MessageBox.Show訊息替換Console.WriteLine為或附加於多行TextBox

要執行範例程式碼,將它貼到包含繼承自 ScrollableControl的型別實例的專案中,例如 a PanelContainerControl。 接著命名實例 ScrollableControl1 ,並確保事件處理程序與事件 Scroll 相關聯。

private void ScrollableControl1_Scroll(Object sender, ScrollEventArgs e) {

System.Text.StringBuilder messageBoxCS = new System.Text.StringBuilder();
messageBoxCS.AppendFormat("{0} = {1}", "ScrollOrientation", e.ScrollOrientation );
messageBoxCS.AppendLine();
messageBoxCS.AppendFormat("{0} = {1}", "Type", e.Type );
messageBoxCS.AppendLine();
messageBoxCS.AppendFormat("{0} = {1}", "NewValue", e.NewValue );
messageBoxCS.AppendLine();
messageBoxCS.AppendFormat("{0} = {1}", "OldValue", e.OldValue );
messageBoxCS.AppendLine();
MessageBox.Show(messageBoxCS.ToString(), "Scroll Event" );
}
Private Sub ScrollableControl1_Scroll(sender as Object, e as ScrollEventArgs) _ 
     Handles ScrollableControl1.Scroll

    Dim messageBoxVB as New System.Text.StringBuilder()
    messageBoxVB.AppendFormat("{0} = {1}", "ScrollOrientation", e.ScrollOrientation)
    messageBoxVB.AppendLine()
    messageBoxVB.AppendFormat("{0} = {1}", "Type", e.Type)
    messageBoxVB.AppendLine()
    messageBoxVB.AppendFormat("{0} = {1}", "NewValue", e.NewValue)
    messageBoxVB.AppendLine()
    messageBoxVB.AppendFormat("{0} = {1}", "OldValue", e.OldValue)
    messageBoxVB.AppendLine()
    MessageBox.Show(messageBoxVB.ToString(),"Scroll Event")

End Sub

備註

Scroll當使用者透過與滾動條互動在客戶端區域捲動,或在控制項間切換時,主動控制項捲入檢視時,事件就會發生。 Scroll這個事件也會發生在你寫程式碼時,例如設定AutoScrollPosition屬性,並且會捲動瀏覽客戶端區域。

你可以在事件處理器中使用該 ScrollOrientation 屬性來決定事件的滾動列方向 Scroll

欲了解更多如何處理事件的資訊,請參閱 「處理與提升事件」。

適用於

另請參閱