Moving form with no border

F

Frank McCown

I've got a form that has no border
(FormBorderStyle.None), and I'd like to move it with the
mouse. My solution is below. Is there a better one?

Private Sub Form1_MouseDown(ByVal sender As Object, ByVal
e As System.Windows.Forms.MouseEventArgs) Handles
MyBase.MouseDown
MouseDownLoc.X = e.X
MouseDownLoc.Y = e.Y
End Sub

Private Sub Form1_MouseMove(ByVal sender As Object, ByVal
e As System.Windows.Forms.MouseEventArgs) Handles
MyBase.MouseMove
If e.Button = MouseButtons.Left Then
Me.Left += e.X - MouseDownLoc.X
Me.Top += e.Y - MouseDownLoc.Y
End If
End Sub
 
H

Herfried K. Wagner [MVP]

* "Frank McCown said:
I've got a form that has no border
(FormBorderStyle.None), and I'd like to move it with the
mouse. My solution is below. Is there a better one?

Private Sub Form1_MouseDown(ByVal sender As Object, ByVal
e As System.Windows.Forms.MouseEventArgs) Handles
MyBase.MouseDown
MouseDownLoc.X = e.X
MouseDownLoc.Y = e.Y
End Sub

Private Sub Form1_MouseMove(ByVal sender As Object, ByVal
e As System.Windows.Forms.MouseEventArgs) Handles
MyBase.MouseMove
If e.Button = MouseButtons.Left Then
Me.Left += e.X - MouseDownLoc.X
Me.Top += e.Y - MouseDownLoc.Y
End If
End Sub

See:

<http://www.google.de/groups?q=sendmessage+HTCAPTION+group:*dotnet*&ie=UTF-8>
 
F

Frank McCown

It appears that another method is to use the ReleaseCapture and
SendMessage API functions. I'm wondering if that isn't creating
additional overhead (although very little) since it requires sending
additional messages. Wouldn't my method be more efficient?

Frank
 
H

Herfried K. Wagner [MVP]

* Frank McCown said:
It appears that another method is to use the ReleaseCapture and
SendMessage API functions. I'm wondering if that isn't creating
additional overhead (although very little) since it requires sending
additional messages. Wouldn't my method be more efficient?

Mhm... You try to reimplement something that is already implemented in
Windows...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top