Solved

Moving a form without a titlebar

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

760 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

17 Experts available now in Live!

Get 1:1 Help Now