Search Tools Links Login

Move a No-Border form by any thing!


Visual Basic 6, or VB Classic

To have a better UI, programmers usually use a borderless form. But there's no caption bar and the form cannot be move. This code help you to move a form by clicking anything that support mousemove, mouseup, mousedown events. See it , it's cool!

Original Author: Kenny Lai, Lai Ho Wa

Code

Dim ism as boolean

 


Public Type POINTAPI
  x As Long
  y As Long
End Type

 

 


Private Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long

 

 


Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long

 

 


 

 



Private Sub lbltitle_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
ism = True
x1 = x + lblTitle.Left
y1 = y + lblTitle.Top
End Sub

 

 


 

 


Private Sub lbltitle_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
If ism = True Then
i = GetCursorPos(Pos)
x2 = Pos.x * Screen.TwipsPerPixelX
y2 = Pos.y * Screen.TwipsPerPixelY
Me.Move (x2 - x1), (y2 - y1)
End If
End Sub

 

 


 

 


Private Sub lbltitle_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
If Me.Top < 0 Then Me.Top = 0
If Me.Left < 0 Then Me.Left = 0
If Me.Top > (Screen.Height - (Me.Height / 10)) Then Me.Top = Screen.Height * 9 / 10
If Me.Left > (Screen.Width - (Me.Width / 10)) Then Me.Left = Screen.Width * 9 / 10
ism = False
End Sub

 

 

 

 

 

 

 

 

 

 

About this post

Posted: 2002-06-01
By: ArchiveBot
Viewed: 99 times

Categories

Visual Basic 6

Attachments

No attachments for this post


Loading Comments ...

Comments

No comments have been added for this post.

You must be logged in to make a comment.