Solved

Moving a form without a titlebar

Posted on 1998-07-18
3
147 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 120 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

896 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now