WinAmp Style - Form Moving

UCM

Centurion
Joined
Jan 1, 2003
Messages
135
Location
Colorado, usa
WinAmp Style - Moving a Form...

Does anyone know how to move a window in code like how winamp does it?

Basically, make a control act just like the titlebar when you hold down the left mouse button on it then move the whole form, just like winamp...

Thanx
 
Last edited:
Try this:

Visual Basic:
Dim Mouse_Offset As Point


    Private Sub [i]YourTitleBar[/i]_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles [i]YourTitleBar[/i].MouseDown
        mouse_offset = New Point(-e.X, -e.Y)
    End Sub

Private Sub [i]YourTitleBar[/i]_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles [i]YourTitleBar[/i].MouseMove
        If e.Button = MouseButtons.Left Then
            Dim mousePos As Point = Control.MousePosition
            mousePos.Offset(mouse_offset.X, mouse_offset.Y)
            Location = mousePos
        End If
    End Sub
 
Sweeeeeeeeeeeeeeeeeeeeeeeeeeet!!!!!!!!!

I_R_Lee, You Rule!!!! that is Exactly what I've been trying to do...


Thanx ah mil!!
 
Also, if you modify the YourTitleBar_MouseDown sub to the following then you can put the control anywhere on your entire projecy and it will work with no problem:
Visual Basic:
  Dim Mouse_Offset As Point

  Private Sub YourTitleBar_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles YourTitleBar.MouseDown
    Mouse_Offset = New Point(-e.X - YourTitleBar.Left, -e.Y - YourTitleBar.Top)
  End Sub

  Private Sub YourTitleBar_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles YourTitleBar.MouseMove
    If e.Button = MouseButtons.Left Then
      Dim mousePos As Point = Control.MousePosition
      mousePos.Offset(Mouse_Offset.X, Mouse_Offset.Y)
      Location = mousePos
    End If
  End Sub


nifty!... YourTitleBar can be anything from a label to a button to even a panel...

NOTE: if you set the form's FormBorderStyle property to 'None' and don't use a mainmenu ( btw, when you set the form's FormBorderStyle to 'none' in code, the mainmenu disappears anyway ) then this worx perfectly...

Theres only 1 issue with this...
As stated above, if you have either a mainmenu or any kind of border then this will be ofset somewhat by those 2 objects so if the user is using large fonts on their computer and they run your program using this code then the ofset will be very noticable if you take into account different sizes of the titlebar/border/mainmenu objects on your computer...

I wonder how we can work around it?

I suppose 1 way is to determin the thinkness of the user's borders and also to determine the size of the mainmenu object...

Any ideas, anyone??
 
Back
Top