VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Move a No-Border form by any thing

by Kenny Lai, Lai Ho Wa (13 Submissions)
Category: VB function enhancement
Compatability: Visual Basic 3.0
Difficulty: Beginner
Date Added: Wed 3rd February 2021
Rating: (2 Votes)

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!

Rate Move a No-Border form by any thing

<<>>

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

 
 
 
 

Download this snippet    Add to My Saved Code

Move a No-Border form by any thing Comments

No comments have been posted about Move a No-Border form by any thing. Why not be the first to post a comment about Move a No-Border form by any thing.

Post your comment

Subject:
Message:
0/1000 characters