在下面的示例中,我们接管了 BaseView.MouseWheel 事件,目的是当鼠标滚轮被旋转时,在 GridView 中执行水平滚动。 通过修改 GridView.LeftCoord 属性值来执行水平滚动。

为了防止默认的垂直滚动被视图执行,当旋转鼠标滚轮时,必须在事件处理程序末尾引发 HideException 异常。

C#CopyCode image复制代码
private void gridView1_MouseWheel(object sender, 
System.Windows.Forms.MouseEventArgs e) {
    GridView view = (sender as GridView);
    view.LeftCoord += e.Delta;
    throw new HideException();
}
Visual BasicCopyCode image复制代码
Private Sub GridView1_MouseWheel(ByVal sender As Object, _
ByVal e As System.Windows.Forms.MouseEventArgs) Handles GridView1.MouseWheel
    Dim view As GridView = CType(sender, GridView)
    view.LeftCoord += e.Delta
    Throw New HideException
End Sub