Results 1 to 10 of 10

Thread: Moving a form

  1. #1

    Thread Starter
    Hyperactive Member mastermind94's Avatar
    Join Date
    Jun 2000
    Location
    Montréal, Canada
    Posts
    441

    Arrow

    How can I move a sub without a title bar like a skin form.



    ----------------
    ICQ:65287451
    AIM:MBR5520
    http://www.sx3k.le-site.net
    [email protected]
    Running VB5 Enterprise Edition

  2. #2
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    You can't move a sub
    Move a form instead (without Title bar)

    Code:
    Private Declare Function SendMessage Lib "User32" _
    Alias "SendMessageA" (ByVal hWnd As Long, _
    ByVal wMsg As Long, _
    ByVal wParam As Long, _
    lParam As Any) As Long
    
    Private Declare Sub ReleaseCapture Lib "User32" ()
    Private Const WM_NCLBUTTONDOWN = &HA1
    Private Const HTCAPTION = 2
    
    Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Dim lngReturnValue As Long
    '// Detect the left mouse button
    If Button = 1 Then
    '// Release the capture of the mouse
    Call ReleaseCapture
    '// Move the form with the mouse
    lngReturnValue = SendMessage(Me.hWnd, WM_NCLBUTTONDOWN, _
    HTCAPTION, 0&)
    End If
    End Sub
    Have fun
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

  3. #3

    Thread Starter
    Hyperactive Member mastermind94's Avatar
    Join Date
    Jun 2000
    Location
    Montréal, Canada
    Posts
    441
    oopss, sotty guys, I did a mistake! Moving a form!

  4. #4
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    hehe No problem mate, I understood that
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

  5. #5
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    Actually you can move a sub just cut and paste *LOL*

  6. #6
    Guest
    Code:
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    Private Declare Function ReleaseCapture Lib "user32" () As Long
    Private Const WM_SYSCOMMAND = &H112
    Private Const SC_MOVE = &HF012
    
    Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
        ReleaseCapture
        SendMessage hwnd, WM_SYSCOMMAND, SC_MOVE, 0
    End Sub

  7. #7
    Guest
    Or to move it without any API:

    Code:
    Dim oldX As Long, oldY As Long, isMoving As Boolean
    
    Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    oldX = X
    oldY = Y
    isMoving = True
    End Sub
    
    Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If isMoving Then
        Me.Top = Me.Top - (oldY - Y)
        Me.Left = Me.Left - (oldX - X)
    End If
    End Sub
    
    Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    isMoving = False
    End Sub

  8. #8
    Guest
    No, that will not work. If you change Me to Picture1, you will be moving the PictureBox, not the Form. In this case, simply place the events in a the PictureBox instead of the Form.

    Code:
    Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
        oldX = X
        oldY = Y
        isMoving = True
    End Sub

  9. #9
    Guest
    Maybe I read it wrong, but isn't that what HeSaidJoe was referring to?

    Then the form only moves via thepicture and
    not the form...
    If you want to move the form using a PictureBox or Label than you just keep it as Me.

  10. #10
    Guest
    As I understand, he wanted to use a PictureBox to simulate a TitleBar, hence, changing Form_(EventName) to Picture1_(EventName) should do it.

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