Windows Develop Bookmark and Share   
 index > Windows Forms General > create a moveable panel in vb.net?
 

create a moveable panel in vb.net?

Hi!

Is It possible to create a moveable panel in vb.net?
Click with mouse over it and move it everywhere!?!?
It's possible?
thank u!

James Alvin  Thursday, March 29, 2007 5:45 AM

Try this:

Code Snippet

Dim XPos As Integer

Dim YPos As Integer

Protected Overrides Sub OnMouseDown(ByVal e As System.Windows.Forms.MouseEventArgs)

If ((e.Button And MouseButtons.Left) _

<> MouseButtons.Left) Then

Return

End If

XPos = (e.X - 8)

YPos = (e.Y - 5)

MyBase.OnMouseDown(e)

End Sub

Protected Overrides Sub OnMouseMove(ByVal e As System.Windows.Forms.MouseEventArgs)

If ((e.Button And MouseButtons.Left) _

<> MouseButtons.Left) Then

Return

End If

If ((e.X > (XPos + 5)) _

OrElse ((e.X < (XPos - 5)) _

OrElse ((e.Y > (YPos + 5)) _

OrElse (e.Y < (YPos - 5))))) Then

Me.Panel1.Left = (e.X - 8)

Me.Panel1.Top = (e.Y - 5)

End If

MyBase.OnMouseMove(e)

End Sub

element109  Thursday, March 29, 2007 6:52 AM

I find a anticle from codeproject

Create your own runtime movable Windows Forms controls

Hope it helps.

Regards!

Gavin Jin - MSFT  Thursday, March 29, 2007 9:12 AM
nobugz  Thursday, March 29, 2007 3:25 PM

Try this:

Code Snippet

Dim XPos As Integer

Dim YPos As Integer

Protected Overrides Sub OnMouseDown(ByVal e As System.Windows.Forms.MouseEventArgs)

If ((e.Button And MouseButtons.Left) _

<> MouseButtons.Left) Then

Return

End If

XPos = (e.X - 8)

YPos = (e.Y - 5)

MyBase.OnMouseDown(e)

End Sub

Protected Overrides Sub OnMouseMove(ByVal e As System.Windows.Forms.MouseEventArgs)

If ((e.Button And MouseButtons.Left) _

<> MouseButtons.Left) Then

Return

End If

If ((e.X > (XPos + 5)) _

OrElse ((e.X < (XPos - 5)) _

OrElse ((e.Y > (YPos + 5)) _

OrElse (e.Y < (YPos - 5))))) Then

Me.Panel1.Left = (e.X - 8)

Me.Panel1.Top = (e.Y - 5)

End If

MyBase.OnMouseMove(e)

End Sub

element109  Thursday, March 29, 2007 6:52 AM

I find a anticle from codeproject

Create your own runtime movable Windows Forms controls

Hope it helps.

Regards!

Gavin Jin - MSFT  Thursday, March 29, 2007 9:12 AM
nobugz  Thursday, March 29, 2007 3:25 PM

You can use google to search for other answers

Custom Search

More Threads

• Drag and drop treenodes from one application to another
• How do you mimic Undo and Redo Lists in toolbar
• adding a NumericUpDown component to the drop down menu
• Browser Control!!
• WriteXml
• Form Closing event question
• drag drop on web browser control
• Download multiple files from webserver.
• Mouse Location Problem
• OnSizeChanged called twice when changing the property Size on a UserControl