ScrollableControl.Scroll 事件
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
用户或代码滚动工作区时发生。
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.ShowConsole.WriteLine或将消息追加到多行TextBox。
若要运行示例代码,请将其粘贴到包含从中继承 ScrollableControl的类型实例的项目(如 Panel 或 ContainerControl)。 然后命名实例 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 。
有关如何处理事件的详细信息,请参阅 处理和引发事件。