2 Replies - 2682 Views - Last Post: 07 October 2010 - 11:09 AM Rate Topic: -----

#1 Joshdw  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 225
  • Joined: 23-March 09

Borderless Form Moving, Small problem

Posted 07 October 2010 - 10:52 AM

SOLVED, Sorry so much lol, The problem was:
mousex = Windows.Forms.Cursor.Position.X - PictureBox1.Left
        mousey = Windows.Forms.Cursor.Position.Y - PictureBox1.Top


Changed the - Picturebox.Left and Top to Me.Left and Top

------


Hello all, I've got a borderless form, and to move it I have the code (shown below), but the problem is that whenever I mousedown on the picturebox, it won't stay where it was, it will go to the top,left of the screen for no reason..

 Dim drag As Boolean
    Dim mousex As Integer
    Dim mousey As Integer
    Private Sub Picturebox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown
        drag = True
        mousex = Windows.Forms.Cursor.Position.X - PictureBox1.Left
        mousey = Windows.Forms.Cursor.Position.Y - PictureBox1.Top
    End Sub
    Private Sub Picturebox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove
        If drag Then
            Me.TopMost = True
            PictureBox1.Top = Windows.Forms.Cursor.Position.Y - mousey
            PictureBox1.Left = Windows.Forms.Cursor.Position.X - mousex
            Me.Left = Windows.Forms.Cursor.Position.X - mousex
            Me.Top = Windows.Forms.Cursor.Position.Y - mousey
        End If
    End Sub
    Private Sub Picturebox1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseUp
        drag = False
    End Sub

This post has been edited by Joshdw: 07 October 2010 - 10:54 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Borderless Form Moving, Small problem

#2 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1623
  • View blog
  • Posts: 5,202
  • Joined: 25-September 09

Re: Borderless Form Moving, Small problem

Posted 07 October 2010 - 10:58 AM

What will, the mouse or the picturebox? If you're talking about the picturebox moving, remark out these lines and see if it gives the results you're wanting.

       If drag Then
            Me.TopMost = True
            'PictureBox1.Top = Windows.Forms.Cursor.Position.Y - mousey
            'PictureBox1.Left = Windows.Forms.Cursor.Position.X - mousex
            Me.Left = Windows.Forms.Cursor.Position.X - mousex
            Me.Top = Windows.Forms.Cursor.Position.Y - mousey
        End If

Was This Post Helpful? 0
  • +
  • -

#3 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1623
  • View blog
  • Posts: 5,202
  • Joined: 25-September 09

Re: Borderless Form Moving, Small problem

Posted 07 October 2010 - 11:09 AM

Or, try this
   Dim drag as boolean
   Dim mousex as Integer
   Dim mousey As Integer
    Private Sub Picturebox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown
        drag = True
        mousex = Windows.Forms.Cursor.Position.X - Me.Left
        mousey = Windows.Forms.Cursor.Position.Y - Me.Top
    End Sub
    Private Sub Picturebox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove
        If drag Then
            Me.TopMost = True
            'PictureBox1.Top = Windows.Forms.Cursor.Position.Y - mousey
            'PictureBox1.Left = Windows.Forms.Cursor.Position.X - mousex

            Me.Left = Windows.Forms.Cursor.Position.X - mousex
            Me.Top = Windows.Forms.Cursor.Position.Y - mousey
        End If
    End Sub
    Private Sub Picturebox1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseUp
        drag = False
    End Sub


I replaced the MouseDown's mousex and mousey with the FORMS left and top (ie, me.left me.top)

This post has been edited by CharlieMay: 07 October 2010 - 11:11 AM

Was This Post Helpful? 1
  • +
  • -

Page 1 of 1