Results 1 to 8 of 8

Thread: Problem with dragging borderless window?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2008
    Posts
    268

    Problem with dragging borderless window?

    Hi everyone,

    I have a borderless window and picturebox GUI, I'm trying to drag the window from it's handles. My code outputs no errors, but it doesn't work either... Any ideas?

    Form = frmMain
    Picturebox = Image1

    Code:
    Private Sub Image1_Click()
    Public Class frmMain
    
    Private mouseOffset As Point
    
    Private isMouseDown As Boolean = False
    
    Private Sub Image1_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs) Handles Image1.MouseDown
    
    Dim xOffset As Integer
    
    Dim yOffset As Integer
    
    If e.Button = Windows.Forms.MouseButtons.Left Then
    
    xOffset = -e.x - SystemInformation.FrameBorderSize.Width
    
    yOffset = -e.y - SystemInformation.FrameBorderSize.Height
    
    mouseOffset = New Point(xOffset, yOffset)
    
    isMouseDown = True
    
    End If
    
    End Sub
    
    Private Sub Image1_MouseMove(ByVal sender As Object, ByVal e As MouseEventArgs) Handles Image1.MouseMove
    
    If isMouseDown Then
    
    Dim mousePos As Point = Control.MousePosition
    
    mousePos.Offset(mouseOffset.X, mouseOffset.Y)
    
    Location = mousePos
    
    End If
    
    End Sub
    
    Private Sub Image1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Image1.MouseUp
    
    isMouseDown = False
    
    End Sub
    
    End Class
    End Sub

  2. #2
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Problem with dragging borderless window?

    Your code doesn't look like it's a correct format for VB6. Also, I see a Private Sub, Image1_MouseDown, within a Private Sub, Image1_Click and you are telling us you get no errors?

    Your code.....
    Code:
    Private Sub Image1_Click()
    Public Class frmMain
    
    Private mouseOffset As Point
    
    Private isMouseDown As Boolean = False
    
    Private Sub Image1_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs) Handles Image1.MouseDown
      '
      '
      '

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2008
    Posts
    268

    Re: Problem with dragging borderless window?

    I wasn't getting errors upon just starting it from VB6, but when I went to make an EXE it did give errors.

    Do you know how I could get this working?

  4. #4
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Problem with dragging borderless window?

    That's hard to believe. Just simply because you have a Sub within a Sub would cause a syntax error from VB6 not to mention the Class statement.

    I don't think this is a VB6 project. Perhaps it is a VB.Net project?

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2008
    Posts
    268

    Re: Problem with dragging borderless window?

    I know it seems hard to believe but for whatever reason it was operating without error. Lol. I got the original code from the MSDN boards, but it was in the VB6 section.

    And yes I am using VB6. Do you know how I could go about this?

  6. #6
    Lively Member
    Join Date
    Mar 2007
    Posts
    88

    Re: Problem with dragging borderless window?

    This is code for dragging the form

    Code:
    Option Explicit
    Dim xx As Single, yy As Single
    
    Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
      If Button <> vbLeftButton Then Exit Sub
      Me.Left = Me.Left + ((X - xx) / 15)
      Me.Top = Me.Top + ((Y - yy) / 15)
    End Sub
    
    Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
      xx = X
      yy = Y
    End Sub
    
    Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
      xx = X
      yy = Y
    End Sub

  7. #7
    Lively Member
    Join Date
    Mar 2007
    Posts
    88

    Re: Problem with dragging borderless window?

    this is the code for the form and picturebox
    Sorry, I am too busy to refine the code but it works


    Code:
    Option Explicit
    Dim xx As Single, yy As Single
    
    Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
      If Button <> vbLeftButton Then Exit Sub
      Me.Left = Me.Left + ((X - xx) / 15)
      Me.Top = Me.Top + ((Y - yy) / 15)
    End Sub
    
    Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
      xx = X
      yy = Y
    End Sub
    
    Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
      xx = X
      yy = Y
    End Sub
    
    '''''''''''''''''''''''''''''''''''''''''''''''''''
    '''''''''''''''''''''''''''''''''''''''''''''''''''
    '''''''''''''''''''''''''''''''''''''''''''''''''''
    
    Private Sub Image1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
      xx = X
      yy = Y
    End Sub
    
    Private Sub Image1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
      xx = X
      yy = Y
    End Sub
    
    Private Sub Image1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
      If Button <> vbLeftButton Then Exit Sub
      Me.Left = Me.Left + (X - xx) / 15
      Me.Top = Me.Top + (Y - yy) / 15
    End Sub
    Last edited by Amr Al-Amir; Jul 28th, 2008 at 10:03 AM.

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2008
    Posts
    268

    Re: Problem with dragging borderless window?

    Works perfect! only required small amount of change, very good.

    Thanks!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width