Solved

Moving a form without a titlebar

Posted on 1998-07-18
3
150 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…

688 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