Move a panel......it's possible?

  • Thread starter Thread starter tranky
  • Start date Start date
T

tranky

i hope you can help me!
It's possible create a moveable panel in vb.net?
Click with mouse over it and move it everywhere!?!?
It's possible?
thank u!
 
Handle the panel's mousedown and mousemove events. Change the panel's
Location when the mouse is down.

See the application after my signature

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.


Public Class Form1

Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()

MyBase.New()

'This call is required by the Windows Form Designer.

InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component list.

Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)

If disposing Then

If Not (components Is Nothing) Then

components.Dispose()

End If

End If

MyBase.Dispose(disposing)

End Sub

'Required by the Windows Form Designer

Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form Designer

'It can be modified using the Windows Form Designer.

'Do not modify it using the code editor.

Friend WithEvents Panel1 As System.Windows.Forms.Panel

<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

Me.Panel1 = New System.Windows.Forms.Panel

Me.SuspendLayout()

'

'Panel1

'

Me.Panel1.BackColor = System.Drawing.Color.Red

Me.Panel1.Location = New System.Drawing.Point(56, 80)

Me.Panel1.Name = "Panel1"

Me.Panel1.TabIndex = 0

'

'Form1

'

Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)

Me.ClientSize = New System.Drawing.Size(368, 310)

Me.Controls.Add(Me.Panel1)

Me.Name = "Form1"

Me.Text = "Form1"

Me.ResumeLayout(False)

End Sub

#End Region

Private _mousedown As Boolean

Private _mousepos As Point



Private Sub Panel1_MouseDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles Panel1.MouseDown

_mousedown = True

_mousepos = New Point(e.X, e.Y)

End Sub

Private Sub Panel1_MouseMove(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles Panel1.MouseMove

If _mousedown Then

Me.Panel1.Location = PointToClient(Me.Panel1.PointToScreen(New Point(e.X -
_mousepos.X, e.Y - _mousepos.Y)))

End If

End Sub

Private Sub Panel1_MouseUp(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles Panel1.MouseUp

_mousedown = False



End Sub

End Class
 
hi cor, i tried your example, but there's a problem:
when i move panel over form dialog, it become hidden and i can't reach it
anymore!
there's a solution?? It's possible move the panel over form dialog and see
it?
I don't speak well english, i hope you understand me.
thank you.
 
for see it over the form dialog you think i must use another form? Panel is
not the right way?

and then: Is possible to block panel when it arrive to the border of form?
in you example, when i move panel over form border, it's become hidden!
 
You would have to verify that the panel doesn't go outside of the form
manually. It'd be pretty simple to check that the location was always inside
the form surface.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
 
Back
Top