Option Explicit
Dim X As Integer, Y As Integer 'Declare variable X and Y as Integer
Private Sub Form_Load()
' This following code to assing variable X and Y with Width and Height of Form
X = Me.Width 'assign variable X with form Width
Y = Me.Height 'assign variable Y with form Height
'This following code to set Width and height of Form To 0
Me.Width = 0 ' Set form Width to 0
Me.Height = 0 ' Set form Height to 0
' This following to centered form
Me.Left = (Screen.Width - Me.Width) / 2 ' Set Left with (Width of your computer screen - Width of form) then Divide it by 2
Me.Top = (Screen.Height - Me.Height) / 2 ' Set Top with (Height of your computer screen - Height of form) then Divide it by 2
End Sub
'THis for Opened Form Animation
Private Sub Timer1_Timer()
'Timer for the opening event
' This following code will bringin back Form Size..
' form will increase width by 400 and Height by 350. So it will seems like animation..
' This following code will bring the Form Width Size
If Me.Width < X Then ' If Width of Form < X (X is Form Width. Look at asiggnment in form load)
Me.Left = (Screen.Width - Me.Width) / 2 'Set Left with (Width of your computer screen - Width of form) then Divide it by 2. This for centered form
Me.Width = Me.Width + 400 ' Form Width will increase by 400 until Width => X
Exit Sub ' Exit this sub if form width is same or more than X
ElseIf Me.Width > X Then 'Else when increasing form width if with more than X then Set to X
Me.Width = X ' Set Form width to X
End If
' This following code will bring the Form Width Size
' Increasing of Height has same explanation like Width
If Me.Height < Y Then
Me.Top = (Screen.Height - Me.Height) / 2
Me.Height = Me.Height + 350
Exit Sub
ElseIf Me.Height > Y Then
Me.Height = Y
End If
Timer1.Enabled = False ' Disable Timer (Stop)
End Sub
'THis for Closing Form Animation
Private Sub Timer2_Timer()
Do While Me.Width > 1800 'this event will running until Form Width
Me.Width = Me.Width - 300 ' Form Width size will decrease by 300
Me.Left = Me.Left + 150 ' Form Left will increase by 150. So form seems like moving to right
If Me.Height - 400 Then '
Me.Top = Me.Top - 1 ' Form Top will decrease by 1
Me.Height = Me.Height - 150 'Form height size will decrease by 150
End If
Me.Refresh ' refresh form
DoEvents
Loop ' loop with condition
Unload Form1: End 'closing form
End Sub Jx_Man
Nearly a Senior Poster
3,329 posts since Nov 2007
Reputation Points: 1,372
Solved Threads: 444