' Unique Form Example - Written completely by Grayda
' firestorm.stormynight.net
' This code shows you how to create cool looking forms to use in your application
' No OCXs are required, and only one form with minimal coding. Please vote, coz I
' need em! :)
' You may use this code, and modify it, as long as you give me lots of credit for it :)
' This declaration allows us to click on and hold onto our title bar or corners for resize (Even if they aren't present)
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
' Lets go of the titlebar or corners
Private Declare Sub ReleaseCapture Lib "user32" ()
' Constant for mouse down
Const WM_NCLBUTTONDOWN = &HA1
' Our titlebar
Const WCAPTION = 2
' The South-Eastern corner of our form, for resizing
Const W_SE_RESIZE = 17
Private Sub Form_Resize()
' Positions the label at 0,0 and spans the entire form
Label1.Move 0, 0, Me.Width
' Positions our information in the center
Label2.Move Me.Width / 2 - Label2.Width / 2, Me.Height / 2 - Label2.Height / 2
' Label3 is our resize button. This code places it in the corner
Label3.Move Me.Width - Label3.Width, Me.Height - Label3.Height
' Label4 is our close button. Slaps it at the end of our form (up the top)
Label4.Move Me.Width - Label4.Width - 100
' Label5 is the minimize button
Label5.Move Me.Width - Label5.Width - Label4.Width - Label6.Width - 150
' Label6 is the maximize and restore button
Label6.Move Me.Width - Label4.Width - 450
End Sub
Private Sub Label1_DblClick()
' When you double click on a form title, it will maximize. This does the same thing
Label6_Click
End Sub
Private Sub Label1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
' Grabs onto our form's titlebar. If you want the focus to follow the mouse, then take away the
' if button = 1 if statement
If Button = 1 Then
ReleaseCapture
SendMessage Me.hwnd, WM_NCLBUTTONDOWN, WCAPTION, 0&
End If
End Sub
Private Sub Label3_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
' This code grabs onto our resize bars and resizes the form. Try replacing W_SE_RESIZE with a
' number between 10 and 17 to see the resizing effects
If Button = 1 Then
ReleaseCapture
SendMessage Me.hwnd, WM_NCLBUTTONDOWN, W_SE_RESIZE, 0&
End If
End Sub
Private Sub Label4_Click()
End
End Sub
Private Sub Label5_Click()
' Minimize the form
Me.WindowState = 1
End Sub
Private Sub Label6_Click()
' Is it maximized? If so, then return it to normal. Else maximize it
If WindowState <> 2 Then
Me.WindowState = 2
Else
WindowState = 0
End If
End Sub