Posted By

simoncoder on 06/12/18


Tagged

form forms move wndproc


Versions (?)

Move a form that has no title


 / Published in: VB.NET
 

Change the borderstyle of the form to "none" and add this code to be able to click anywhere and move the form.

  1. #Region "Move the Form Click anywhere"
  2. Private _location As Point
  3.  
  4. Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
  5. _location = e.Location
  6.  
  7. End Sub
  8.  
  9. Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
  10. If String.Compare(Control.MouseButtons.ToString(), "Left") = 0 Then
  11.  
  12. Dim MSize As New Size(_location)
  13. MSize.Width = e.X - _location.X
  14. MSize.Height = e.Y - _location.Y
  15. Me.Location = Point.Add(Me.Location, MSize)
  16.  
  17. End If
  18. End Sub
  19. #End Region

Report this snippet  

You need to login to post a comment.