Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Move form with BorderStyle=0 (None)

Status
Not open for further replies.

Helen1greece

Technical User
Jun 4, 2003
85
GR
How can I move a form which has BorderStyle=0 (None)? I want to do it by clicking and dragging on a label which is on the form. Can somebody give me an example code?
 
Dim LeftX As Long
Dim TopY As Long

Private Sub Label1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
LeftX = X
TopY = Y
End Sub

Private Sub label1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button And 1 Then
Me.Left = Me.Left + X - LeftX
Me.Top = Me.Top + Y - TopY
End If
End Sub
 
Originally based on an MS example:
[tt]
Option Explicit

Private Declare Sub ReleaseCapture Lib "User32" ()
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
Const WM_NCLBUTTONDOWN = &HA1
Const HTCAPTION = 2


Private Sub Label1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim lngReturnValue As Long

If Button = 1 Then
Call ReleaseCapture
lngReturnValue = SendMessage(Form1.hWnd, WM_NCLBUTTONDOWN, HTCAPTION, 0&) ' should really check returned value for success...
End If

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top