user2494051 user2494051 - 6 months ago 31
Vb.net Question

Adding a transition effect to a winform?

I want to know if there is a way that I can add transition effects to my winforms.

I have about 3 winforms on my application (vb.net) that open at the top of the screen. My client is concerned with aesthetics, so transitions is one requirements for the forms to show up when called.

Maybe transition is not accurate. What I mean is having the form move from left to right when called. or top to bottom.

Are there any resources, to help accomplish this?

Answer

The simplest way is to use a Timer and increase Opacity in a few steps over a second or two.

http://msdn.microsoft.com/library/system.windows.forms.form.opacity.aspx

An example:

Form1:

Public Class Form1

    Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
        Dim f As Form2
        f = New Form2
        f.Timer1.Enabled = True
        f.Timer1.Interval = 5
        f.Opacity = 0
        f.ShowDialog(Me)
    End Sub

End Class

Form2:

Public Class Form2
    Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
        If Me.Opacity >= 1 Then
            Timer1.Stop()
            Exit Sub
        End If
        Me.Opacity += 0.05
    End Sub
End Class
Comments