- Joined
- Dec 22, 2007
- Messages
- 184 (0.03/day)
- Location
- Central Nebraska
System Name | CORSAIR |
---|---|
Processor | AMD Phenom 1090T x6 @3.2 |
Motherboard | Gigabyte Ga-78LMT-S2P |
Cooling | High efficiency dust cooling |
Memory | 8GB GSkill DDR3 1333 |
Video Card(s) | Sapphire Radeon HD3870 512MB GDDR4 PCI-e toxic |
Storage | Seagate SV35.3 ST3250310SV 250GB SATAII(Windows 7 Pro x64), 320GB Samsung SATAII(Storage and SuSE) |
Display(s) | Dell 20" LCD, Dell 17" LCD |
Power Supply | Antec Cool Blue 650W Modular |
Software | Windows 7 Professional SP1, Visual Studio 2010 Ultimate |
So I have an app using the same method as the sample below to create scrollable controls on a windows form. This is a commonly found solution/method on how to create smart-phone like scrolling on a vb.net winform which uses a flowlayoutpanel with the autoscroll property set to true with some handlers to handle the touching of individual controls on the flowlayoutpanel, however, if you touch the actual flowlayoutpanel itself (say there is an area which does not have a control on it), the native scrolling takes over and works, and then prevents the handlers of the child objects until the application is restarted.
You should be able to paste the following into a new project and run it and see... touching the buttons and sliding your finger up/down works, however, if you scroll to the area at the bottom where buttons are not populated (on purpose for this error demo), you will see that you can scroll still, until you try to scroll the buttons again, which you must double tap and hold in order to scroll after that.
I am wondering if anyone can figure this out? I seem to be quite stumped with this one.
You should be able to paste the following into a new project and run it and see... touching the buttons and sliding your finger up/down works, however, if you scroll to the area at the bottom where buttons are not populated (on purpose for this error demo), you will see that you can scroll still, until you try to scroll the buttons again, which you must double tap and hold in order to scroll after that.
Code:
Public Class Form1
Dim FlowPanel As New FlowLayoutPanel
Public MouseDepressed As Boolean = False
Private Function GenerateButton(ByVal pName As String) As Button
Dim mResult As New Button
With mResult
.Name = pName
.Text = pName
.Width = 128
.Height = 128
.Margin = New Padding(3, 3, 3, 3)
.Padding = New Padding(0)
.BackColor = Color.CornflowerBlue
AddHandler .MouseDown, AddressOf Button_MouseDown
AddHandler .MouseMove, AddressOf Button_MouseMove
End With
Return mResult
End Function
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
Me.Width = 806
Me.Height = 480
FlowPanel.Padding = New Padding(0)
FlowPanel.Margin = New Padding(0)
FlowPanel.Dock = DockStyle.Fill
FlowPanel.AutoScroll = True
Me.Controls.Add(FlowPanel)
FlowPanel.AutoSize = False
Dim i As Integer
For i = 1 To 98
FlowPanel.Controls.Add(GenerateButton("btn" & i.ToString))
Next
AddHandler FlowPanel.MouseDown, AddressOf Button_MouseDown
End Sub
Dim myMouseDownPoint As Point
Dim myCurrAutoSMouseDown As Point
Public Declare Auto Function SetCursorPos Lib "User32.dll" (ByVal X As Integer, ByVal Y As Integer) As Long
Public Declare Auto Function GetCursorPos Lib "User32.dll" (ByRef lpPoint As Point) As Long
Public Declare Sub mouse_event Lib "user32" Alias "mouse_event" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
Public Const MOUSEEVENTF_LEFTUP = &H4 '
Private Sub Panel_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs)
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
End Sub
Private Sub Button_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs)
myMouseDownPoint = PointToClient(Cursor.Position)
myCurrAutoSMouseDown = FlowPanel.AutoScrollPosition
MouseDepressed = True
End Sub
Private Sub Button_MouseMove(ByVal sender As Object, ByVal e As MouseEventArgs)
If e.Button = Windows.Forms.MouseButtons.Left Then
If MouseDepressed = True Then
Dim mLocation As Point = PointToClient(Cursor.Position)
If myMouseDownPoint <> mLocation Then
Dim mCurrAutoS As Point
Dim mDeslocation As Point = myMouseDownPoint - mLocation
mCurrAutoS.X = Math.Abs(myCurrAutoSMouseDown.X) + mDeslocation.X
mCurrAutoS.Y = Math.Abs(myCurrAutoSMouseDown.Y) + mDeslocation.Y
FlowPanel.AutoScrollPosition = mCurrAutoS
End If
End If
End If
End Sub
End Class
I am wondering if anyone can figure this out? I seem to be quite stumped with this one.