Solved

Moving a form without a titlebar

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

Industry Leaders: 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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

749 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