Results 1 to 6 of 6

Thread: [RESOLVED] Moving a Borderless form

  1. #1

    Thread Starter
    Member
    Join Date
    Sep 2009
    Posts
    36

    Resolved [RESOLVED] Moving a Borderless form

    I am making a project where the borderstyle of the form is 0. how do i make it move with a label and it it called label1
    EDIT: Resolved!
    Last edited by young.dragon; Dec 10th, 2009 at 07:41 PM. Reason: Resolved

  2. #2
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    Re: Moving a Borderless form

    Heres 3 ways to do that,

    ' Using APIs
    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 Long) As Long
    Private Declare Function ReleaseCapture Lib "user32" () As Long
    Private Const WM_NCLBUTTONDOWN = &HA1
    Private Const HTCAPTION = 2
    
    Private Sub Label1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
        If Button = vbLeftButton Then
            ReleaseCapture
            SendMessage Me.hwnd, WM_NCLBUTTONDOWN, HTCAPTION, 0&
            ' note code continues here on mouse up.
        End If
    End Sub
    ' Using VB code only #1
    Code:
    Option Explicit
    Private lngX As Long
    Private lngY As Long
    
    Private Sub Label1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
        If Button = vbLeftButton Then
            lngX = X
            lngY = Y
        End If
    End Sub
    
    Private Sub Label1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
        If Button = vbLeftButton Then Me.Move Me.Left + X - lngX, Me.Top + Y - lngY
    End Sub
    ' Using VB code only #2
    Code:
    Private Sub Label1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
        If Button = vbLeftButton Then Label1.Tag = X & "|" & Y
    End Sub
    
    Private Sub Label1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
        Label1_MouseMove Button, Shift, X, Y
    End Sub
    
    Private Sub Label1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
        Dim lngLeft As Long, lngTop As Long, sngX As Single, sngY As Single
        If Button = vbLeftButton And LenB(Label1.Tag) Then
            sngX = Split(Label1.Tag, "|")(0)
            sngY = Split(Label1.Tag, "|")(1)
            lngLeft = Me.Left + X - sngX
            lngTop = Me.Top + Y - sngY
            Me.Move lngLeft, lngTop
        End If
    End Sub
    Last edited by Edgemeal; Dec 12th, 2009 at 06:24 PM. Reason: condensed to single response

  3. #3

    Thread Starter
    Member
    Join Date
    Sep 2009
    Posts
    36

    Re: Moving a Borderless form

    Thank you!

  4. #4
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    Re: Moving a Borderless form

    Quote Originally Posted by young.dragon View Post
    Thank you!
    Here's yet another way, VB code only...
    Code:
     Code moved to post #2.
    Last edited by Edgemeal; Dec 12th, 2009 at 06:25 PM.

  5. #5
    PowerPoster ThEiMp's Avatar
    Join Date
    Dec 2007
    Location
    Take The PCI Bus Across To The CPU!!
    Posts
    3,948

    Re: Moving a Borderless form

    Also set the Form property to this:
    Code:
    Form1.Moveable = True
    I have a huge free products range, of computer software in which you can download using any kind of 64-Bit Web Browser. Also there is coming a Social Networking section that I am making on my Website...

    |Ambra Productions Inc. | The Black Sun Society | The Black Shield | Ambra College | Church of the Black Sun | Ambra Productions Inc's Homepage | Boomtick Venues: Ambar Nightclub, Jack Rabbit Slim's, Villa Nightclub and Lucy's Love Shack | Pasta Ambra | Fish Feast Company | Wallet Wizard | Ambrose Liquor | Ambar Tavern | Ambra University | Ambra Cheese |

    Do you wish to do unpaid work for me??? If so, the PM me on this Forum, and then we can get to work, programming for the future of computers go by the name of ThEiMp. This is my ghost writers name. Also my nickname, means that I am: The Imperial of the Technology Industry, so then to make it really short, I just then wrote: The Imp, which is where I get the nickname from...

  6. #6
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Moving a Borderless form

    If this is solved to your satisfaction, could you please do us a little favour, and mark the thread as Resolved? (editing the first post to add that word is far from obvious)
    (this saves time reading for those of us who like to answer questions, and also helps those who search to find answers)

    You can do it by clicking on "Thread tools" just above the first post in this thread, then "Mark thread resolved". (like various other features of this site, you need JavaScript enabled in your browser for this to work).

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