Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools

Move Form without title bar (2 different methods)
[ All Languages » VB »  Windows]

Total Hit ( 3992)

Rate this article:     Poor     Excellent 

 Submit Your Question/Comment about this article

Rating


 


You can move a form which has no titlebar by 2 different methods. First method will not show any drag border while second method will show drag borders.

Click here to copy the following block
'//////////////////////////////////////////////////////////
'// Move Form Without Title bar (Method-1: Without drag border)
'//////////////////////////////////////////////////////////

Private Declare Function ReleaseCapture Lib "user32" () As Long
Private Declare Function SetCapture Lib "user32" (ByVal hwnd As Long) As Long
Private bMoving As Boolean  ' flag to indicate drag operation
Private sngXStart As Single ' original mouse X offset
Private sngYStart As Single ' original mouse Y offset

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
  If Button <> 1 Then Exit Sub  ' only left button
  SetCapture Me.hwnd    ' Get all mouse events
  sngXStart = X      ' save current offset
  sngYStart = Y
  bMoving = True      ' start move
End Sub

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, _
 X As Single, Y As Single)
  If Not bMoving Then Exit Sub  ' ignore if not moving
  ' move form so that new mouse position is same as original
  Me.Move Me.Left - sngXStart + X, Me.Top - sngYStart + Y
End Sub

Private Sub Form_MouseUp(Button As Integer, Shift As Integer, _
 X As Single, Y As Single)
  If Not bMoving Then Exit Sub  ' ignore if not moving
  ReleaseCapture      ' stop the moving operation
  bMoving = False
End Sub

And here is the second approach to do the same thing

Click here to copy the following block
'//////////////////////////////////////////////////////////
'// Move Form Without Title bar (Method-2: With Drag border)
'//////////////////////////////////////////////////////////
'Declares for Moving a Form with no Titlebar or Caption
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" ( _
    ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Long) As Long

Private Declare Function ReleaseCapture Lib "user32" () As Long

Const WM_NCLBUTTONDOWN = &HA1
Const HTCAPTION = 2

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
  If Button <> 1 Then Exit Sub  ' only left button
  ReleaseCapture

  SendMessage hwnd, WM_NCLBUTTONDOWN, _
      HTCAPTION, 0&

  '// Or use:
  ' SendMessage hwnd, WM_SYSCOMMAND, &HF012&, 0&

  bMoving = True      ' start move
End Sub

Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
  If Not bMoving Then Exit Sub  ' ignore if not moving

  ReleaseCapture      ' stop the moving operation
  bMoving = False
End Sub



Submitted By : Nayan Patel  (Member Since : 5/26/2004 12:23:06 PM)

Job Description : He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.
View all (893) submissions by this author  (Birth Date : 7/14/1981 )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.