For Programmers: Free Programming Magazines  


Home > Archive > Visual Basic > October 2004 > Form Move









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Form Move
Sharrukin Amiri

2004-10-29, 3:55 pm

Hello,

How do you permit a client to move a form, with 'BorderStyle Property set to
none, in realtime? Any guideline on how to do this?

Thanks!

Sharrukin



Tom Esh

2004-10-29, 3:55 pm

On Fri, 29 Oct 2004 12:02:02 -0700, "Sharrukin Amiri"
<sharrukin@amtekcenter.com> wrote:

>How do you permit a client to move a form, with 'BorderStyle Property set to
>none, in realtime? Any guideline on how to do this?


Here's a popular method that works by using the Api to tell Windows a
mousedown has occurred on the titlebar. Works even if it has no
titlebar (providing you have not set the form's Moveable prop to
False).

'declaration section...
Private Const WM_NCLBUTTONDOWN = &HA1&
Private Const HTCAPTION = 2&
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 Function ReleaseCapture Lib "user32" () As Long


'code....
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, _
x As Single, y As Single)
If Button = vbLeftButton Then
ReleaseCapture
SendMessage Me.hwnd, WM_NCLBUTTONDOWN, HTCAPTION, ByVal 0&
End If
End Sub


-Tom
MVP - Visual Basic
(please post replies to the newsgroup)
J French

2004-10-30, 3:55 pm

On Fri, 29 Oct 2004 12:02:02 -0700, "Sharrukin Amiri"
<sharrukin@amtekcenter.com> wrote:

>Hello,
>
>How do you permit a client to move a form, with 'BorderStyle Property set to
>none, in realtime? Any guideline on how to do this?


Option Explicit

Private Declare Function ReleaseCapture _
Lib "user32" () As Long
Private Declare Function SendMessage _
Lib "user32" _
Alias "SendMessageA" _
(ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
ByVal lParam As Any) As Integer
Const WM_NCLBUTTONDOWN = &HA1
Const HTCAPTION = 2

Public Sub MoveObject(hwnd As Long)
ReleaseCapture
SendMessage hwnd, WM_NCLBUTTONDOWN, HTCAPTION, 0&
End Sub

Private Sub Form_MouseDown(Button As Integer, _
Shift As Integer, _
X As Single, _
Y As Single)
MoveObject Me.hwnd
End Sub



Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com