move a form without the title bar code taken from microsoft game example

Public Class MainForm

Dim matrix As Guid

Dim score As Integer = 0

Private mouseOffset As Point

Private paused As Boolean = False

Private isSoundOn As Boolean = True

 

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

mouseOffset = New Point(-e.X, -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 = Windows.Forms.MouseButtons.Left Then

Dim mousePos As Point = Control.MousePosition

mousePos.Offset(mouseOffset.X, mouseOffset.Y)

Location = mousePos

End If

End Sub

 

Private Sub MainForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

End Sub





this really works just past onto your form1.vb i been trying to get this code working for nearly 2 days but now i have and will finish my project now :P laters Big Smile



Answer this question

move a form without the title bar code taken from microsoft game example

  • starsky

    why isnt this code working again i done the same thing copy and pasted onto the new form1 i made did someone change the code in my post or what
  • Runaway

    well here is another code sample moving a form without title window err


    Public Class MainForm1

    Dim matrix As MainForm1

    Dim score As Integer = 0

    Private mouseOffset As Point

    Private paused As Boolean = False

    Private isSoundOn As Boolean = True

    'If there is no title bar, you can move the form just by dragging it.

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

    mouseOffset = New Point(-e.X, -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 = Windows.Forms.MouseButtons.Left Then

    Dim mousePos As Point = Control.MousePosition

    mousePos.Offset(mouseOffset.X, mouseOffset.Y)

    Location = mousePos

    End If

    End Sub

     

     

     

     

    Private Sub optionsMenu_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub

    End Class


    do not change code-


  • move a form without the title bar code taken from microsoft game example