Change background image
  1. What's up? I see you're viewing as a Guest. How about registering, it only takes like 2 minutes. This will enable you to do more on our forum and stay updated.

Moving Borderless Forms [Best Way]

Discussion in 'Developer General' started by 3nvisi0n, Jun 27, 2011.

Thread Status:
This thread is more than 180 days old.
  1. 3nvisi0n

    3nvisi0n The R3v0lu710n Super-Mod


    I ran across this problem in another thread, and figured I'd cover the easy way of doing this.

    The basic problem is that when in Visual Basic you create a form with a custom skin you normally turn off the borders so you can put your own buttons in and title bar and stuff. But this means there is no title bar for the user to click and drag around.

    The normal solution is to create an object and just track the mouse down to mouse release events moving the form along as it goes. This works indeed but it is kinda like using brute force to get into your home when you have the key. It is a better idea to use the system calls and handle it as though it were a real title bar. That way you do not bypass the settings the user may have on their computer to speed up their display(like for myself I through a windows setting only display a window border when moving it, not the entire thing) This enables that to work...are you ready for this super complex code...

    Just copy and paste this into your Form code.

    Protected Overrides Sub WndProc(ByRef e As Message)
            If e.Msg = &H84 AndAlso e.Result.ToInt32() = 1 Then e.Result = New IntPtr(2)
        End Sub
    Thats it. Copy and paste that and if a user clicks on any empty space on your form and drags, the action will be performed...

    Now if you want it to only happen in a certain area it gets a little trickier(gotta edit the If line, I'll make a tutorial on that later since I need to brush up on the hex codes)
Thread Status:
This thread is more than 180 days old.

Share This Page