Help with Slider form function

TyB

Well-known member
Joined
May 14, 2009
Messages
102
Programming Experience
3-5
I am trying to make a form expand from one size to another using a slider animation.

The problem is when I run it the form resizes but without the animation. I'm not sure how to use the animation when resizing the form. It works if the form is a set size and then I run the animation.

The form is borderless and starts out with a width of 11 and I want the final width to be 285.

The resize and animation are triggered by clicking on the form.

Here is the code.

Private Sub Form3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Click
Me.Width = mintformmaxwidth
animateWin(Me, True)
End Sub

Module code

Module Module1
'Global variable
Public mintformmaxwidth As Integer

Public Enum AnimateWindowFlags
AW_HOR_POSITIVE = &H1
AW_HOR_NEGATIVE = &H2
AW_VER_POSITIVE = &H4
AW_VER_NEGATIVE = &H8
AW_CENTER = &H10
AW_HIDE = &H10000
AW_ACTIVATE = &H20000
AW_SLIDE = &H40000
AW_BLEND = &H80000
End Enum
Dim f1 As Form1
Public Declare Auto Function AnimateWindow Lib "user32" (ByVal hwnd As IntPtr, ByVal time As Integer, ByVal flags As AnimateWindowFlags) As Boolean
Sub Main()
f1 = New Form1
Dim xx As Integer = Screen.PrimaryScreen.Bounds.Width - f1.Size.Width
Dim yy As Integer = Screen.PrimaryScreen.Bounds.Height / 2 - (f1.Size.Height / 2)
f1.Location = New Point(xx, yy)
Application.Run(f1)
End Sub
Sub animateWin(ByVal frmToAnimate As Form, ByVal showForm As Boolean)
If showForm Then
AnimateWindow(frmToAnimate.Handle, 1000, AnimateWindowFlags.AW_HOR_NEGATIVE Or AnimateWindowFlags.AW_SLIDE)
Else : AnimateWindow(frmToAnimate.Handle, 2000, AnimateWindowFlags.AW_HOR_POSITIVE Or AnimateWindowFlags.AW_HIDE)
End If

End Sub
End Module

Thanks for any help,
Ty
 
Back
Top