Move a No-Border form by any thing!

Submitted on: 1/17/2015 11:24:00 PM
By: Kenny Lai, Lai Ho Wa (from psc cd)  
Level: Beginner
User Rating: By 2 Users
Compatibility: VB 3.0, VB 4.0 (16-bit), VB 4.0 (32-bit), VB 5.0, VB 6.0
Views: 2042
     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!


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

Other 11 submission(s) by this author


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this article (in the Beginner category)?
(The article with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)

Other User Comments

 There are no comments on this submission.

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular article, please click here instead.)

To post feedback, first please login.