使用触摸屏滚动面板,同时拖动面板的控件

时间:2017-01-20 18:24:57

标签: vb.net winforms scrollbar panel touchscreen

我的表单有一个可滚动的面板,可以使用触摸屏监视器滚动。我的面板将包含一个带有按钮的TableLayoutPanel。无论我的光标在哪里,我都可以使用MouseWheel滚动Panel。使用触摸屏时,我只能在手指滑过TableLayoutPanel周围的空白区域时滚动面板,而不是在TableLayoutPanel本身内。

有没有办法将除MouseClick以外的任何内容传递给基础Panel?

暂时忽略TableLayoutPanel,这是一个简单的例子,说明了我一直在尝试使用Panel和高按钮。

Public Class Form1

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
    Dim p As New Panel
    With p
        .Top = 0
        .Left = 0
        .Width = Me.ClientSize.Width
        .Height = Me.ClientSize.Height

        p.BackColor = Color.LightBlue

        .HorizontalScroll.Maximum = 0
        .AutoScroll = False
        .VerticalScroll.Visible = False
        .AutoScroll = True
    End With
    Me.Controls.Add(p)

    Dim b As New MyButton
    With b
        .Top = 0
        .Left = 0
        .Width = 400
        .Height = 1000

        b.BackColor = Color.LightCoral
    End With
    AddHandler b.Click, Sub() MessageBox.Show("Clicked!")
    p.Controls.Add(b)

End Sub

Private Class MyButton
    Inherits Button

    Protected Overrides Sub WndProc(ByRef m As Message)
        Dim HTTRANSPARENT As Integer = -1
        Dim WM_LBUTTONDOWN As Integer = &H201
        Dim WM_VSCROLL As Integer = &H115
        Dim WM_MOUSEMOVE As Integer = &H200
        Dim WM_MOUSEWHEEL As Integer = &H20A
        Dim WM_NCMOUSEHOVER As Integer = &H2A0
        Dim WM_MOUSEHOVER As Integer = &H2A1


        If m.Msg = WM_VSCROLL _
        OrElse m.Msg = WM_MOUSEMOVE _
        OrElse m.Msg = WM_MOUSEWHEEL _
        OrElse m.Msg = WM_NCMOUSEHOVER _
        OrElse m.Msg = WM_MOUSEHOVER Then
            m.Result = CType(HTTRANSPARENT, IntPtr)
        End If
        MyBase.WndProc(m)
    End Sub

End Class

End Class

0 个答案:

没有答案