Results 1 to 4 of 4
  1. #1
    MinimalKills's Avatar
    Join Date
    Sep 2008
    Gender
    male
    Posts
    46
    Reputation
    10
    Thanks
    6

    Post How to Move Form

    I need help with moving a form that has no titlebar.
    I want to be able to grab a label and drag the form around with it.

    Ive tried this but it doesnt work.

    Code:
    Dim DragOn As Boolean
    Dim OldX As Single
    Dim OldY As Single
    Dim NewX As Single
    Dim NewY As Single
    
    Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
        DragOn = True
        OldX = X
        OldY = Y
    End Sub
    
    Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
        DragOn = False
    End Sub
    
    Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
        If DragOn Then
            NewX = X
            NewY = Y
            Me.Top = Me.Top + (NewY - OldY)
            Me.Left = Me.Left + (NewX - OldX)
            OldX = NewX
            OldY = NewY
        End If
    End Sub
    and this..

    Code:
    Option Explicit
    
    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 HTCAPTION = 2
    Private Const WM_NCLBUTTONDOWN = &HA1
    
    Private Sub Label1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
        ReleaseCapture
        SendMessage Me.hwnd, WM_NCLBUTTONDOWN, HTCAPTION, 0&
    End Sub

  2. #2
    Pixie's Avatar
    Join Date
    Apr 2009
    Gender
    male
    Location
    Pixie wird wieder steigen.
    Posts
    1,884
    Reputation
    22
    Thanks
    229
    My Mood
    Fine
    [YOUTUBE]<object width="425" height="344"><param name="movie" value="https://www.youtube.com/v/tBsizued0Ko&hl=en_US&fs=1&"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="https://www.youtube.com/v/tBsizued0Ko&hl=en_US&fs=1&" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object>[/YOUTUBE]

    Try that and tell me results.

  3. #3
    Zoom's Avatar
    Join Date
    May 2009
    Gender
    male
    Location
    Your going on my 24/7 DDoS hit list.
    Posts
    8,552
    Reputation
    127
    Thanks
    5,970
    My Mood
    Happy
    Quote Originally Posted by PixieCorp View Post
    [YOUTUBE]<object width="425" height="344"><param name="movie" value="https://www.youtube.com/v/tBsizued0Ko&hl=en_US&fs=1&"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="https://www.youtube.com/v/tBsizued0Ko&hl=en_US&fs=1&" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object>[/YOUTUBE]

    Try that and tell me results.
    Yeah I think it´s the same!
    -Rest in peace leechers-

    Your PM box is 100% full.

  4. #4
    trevor206's Avatar
    Join Date
    Dec 2008
    Gender
    male
    Posts
    324
    Reputation
    12
    Thanks
    107
    Quote Originally Posted by MinimalKills View Post
    I need help with moving a form that has no titlebar.
    I want to be able to grab a label and drag the form around with it.

    Ive tried this but it doesnt work.

    Code:
    Dim DragOn As Boolean
    Dim OldX As Single
    Dim OldY As Single
    Dim NewX As Single
    Dim NewY As Single
    
    Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
        DragOn = True
        OldX = X
        OldY = Y
    End Sub
    
    Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
        DragOn = False
    End Sub
    
    Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
        If DragOn Then
            NewX = X
            NewY = Y
            Me.Top = Me.Top + (NewY - OldY)
            Me.Left = Me.Left + (NewX - OldX)
            OldX = NewX
            OldY = NewY
        End If
    End Sub
    and this..

    Code:
    Option Explicit
    
    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 HTCAPTION = 2
    Private Const WM_NCLBUTTONDOWN = &HA1
    
    Private Sub Label1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
        ReleaseCapture
        SendMessage Me.hwnd, WM_NCLBUTTONDOWN, HTCAPTION, 0&
    End Sub
    Code:
    Const WM_NCHITTEST As Integer = &H84
        Const HCLIENT As Integer = &H1
        Const HTCAPTION As Integer = &H2
    
    
    
        Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
            Select Case m.Msg
                Case WM_NCHITTEST
                    MyBase.WndProc(m)
                    If m.Result = HCLIENT Then m.Result = HTCAPTION
                Case Else
                    MyBase.WndProc(m)
            End Select
        End Sub
    Thanks me if i helped

  5. The Following User Says Thank You to trevor206 For This Useful Post:

    Pixie (11-14-2009)

Similar Threads

  1. TUT]How to move a borderless form[TUT
    By XGelite in forum Visual Basic Programming
    Replies: 7
    Last Post: 11-14-2009, 03:11 PM
  2. [Help] How to move files?
    By guza44_44 in forum Visual Basic Programming
    Replies: 6
    Last Post: 11-05-2009, 01:26 AM
  3. How to: Move a File in Visual Basic
    By Pixie in forum Visual Basic Programming
    Replies: 12
    Last Post: 09-14-2009, 08:04 PM
  4. Replies: 1
    Last Post: 05-12-2009, 02:32 PM

Tags for this Thread