Jump to content

Movable windows form

- - - - -

  • Please log in to reply
2 replies to this topic

#1
xXAlphaXx

xXAlphaXx

    Learning Programmer

  • Members
  • PipPipPip
  • 85 posts
Okay, so I was able to get my window the way I wanted it, their is no border at the top and the whole window is just the picture.

Now I would like users to be able to click anywhere on the form and be able to move it around like they were clicking on the border.

#2
gregwarner

gregwarner

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 856 posts
  • Location:Arkansas
There is a blog post here at this site that shows you how to do that:
Microsoft .NET: Move form by clicking anywhere on its surface

Here's the code taken from that page:

Dim a, b As Integer

Dim newPoint As New System.Drawing.Point()


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

    a = Me.MousePosition.X - Me.Location.X

    b = Me.MousePosition.Y - Me.Location.Y

End Sub


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

    If e.Button = MouseButtons.Left Then

        newPoint = Me.MousePosition

        newPoint.X = newPoint.X - a

        newPoint.Y = newPoint.Y - b

        Me.Location = newPoint

    End If

End Sub


Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.

– Douglas Hofstadter, Gödel, Escher, Bach: An Eternal Golden Braid


#3
xXAlphaXx

xXAlphaXx

    Learning Programmer

  • Members
  • PipPipPip
  • 85 posts
Wow, that worked perfectly, thank you!

This is one snippet of code I am definitely saving.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users