?
Solved

Moving a form without a titlebar

Posted on 1998-07-18
3
Medium Priority
?
154 Views
Last Modified: 2010-05-03
I'd like to be able to move a form around on the screen by clicking anywhere in the form and dragging it around.  How do I this?  I think this involves the form.move function, but I'm not totally sure.  Thanx in advance.
-Zach
0
Comment
Question by:zakthewak
  • 2
3 Comments
 
LVL 6

Accepted Solution

by:
alamo earned 480 total points
ID: 1466189
There's an easier method using the Windows API. Here's the code (a slightly edited version of MS KB article Q173773):

In General section of form:

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" ()
Const WM_NCLBUTTONDOWN = &HA1
Const HTCAPTION = 2

In the Form_MouseMove function:

Dim lngReturnValue As Long
If Button = 1 Then
    Call ReleaseCapture
    lngReturnValue = SendMessage(Form2.hWnd, WM_NCLBUTTONDOWN, HTCAPTION, 0&)
End If

This works by watching for the mose moving over the form, and when it does (and the left mouse button is down) sending the same message to Windows that gets sent when you click on the title bar.

Hope this helps!
0
 
LVL 6

Expert Comment

by:alamo
ID: 1466190
And of course you need to change Form2 to your form name (though using Me should work too, if I had noticed it in time that would have made the example code a little more generic).
0
 

Author Comment

by:zakthewak
ID: 1466191
Thanx a lot alamo!  That works perfectly.  =)
Thank you once again.

-Zach
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month16 days, 10 hours left to enroll

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question