Results 1 to 40 of 45

Thread: Nice fading in and out form effect

Threaded View

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    May 2007
    Posts
    279

    Smile Nice fading in and out form effect

    Hi,

    A while ago I designed a small subroutine that would allow me to fade forms in and out. The effect is very nice and adds a bit of sleekness to your application. There is also a C# version, this can be found in the C# codebank here

    Code:
        Sub FormFade(ByVal FType)
            Select Case FType
                Case ("in")
                    Dim FadeCount As Integer
                    For FadeCount = 10 To 90 Step 10
                        Me.Opacity = FadeCount / 100
                        Me.Refresh()
                        Threading.Thread.Sleep(50)
                    Next
                Case ("out")
                    Dim FadeCount As Integer
                    For FadeCount = 90 To 10 Step -10
                        Me.Opacity = FadeCount / 100
                        Me.Refresh()
                        Threading.Thread.Sleep(50)
                    Next
            End Select
            Me.Opacity = 99
    
        End Sub
    This subroutine can be called like this:

    FormFade("in") for fading your form in
    FormFade("out") for fading your form out

    The form fade in can be implemented on your Form Load event handler like so:

    Code:
      Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            FormFade("in")
        End Sub
    The form fade out can be implemented on your Form Closing event handler as it will catch all attempts to close, not just ones you might add to your Command Button. This can be implemented like this:

    Code:
        Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
            FormFade("out")
        End Sub
    Additional Information

    This should work with all versions of .net

    As you have seen I have set Me.Opacity = 99. This is for two reasons. One being that the fade in effect does not fully reach the 100/99% so the form does not look solid. The second is that if fading out with 100% opacity the form will glitch slightly. You will notice no difference between 99% and 100% opacity though.

    I'd love to know what you think of this, yes it's not original, but for those looking for something like this, I think it is a good little script.
    Last edited by samtheman; Oct 9th, 2008 at 01:08 PM.
    If you found any of my posts helpful then please rate them.

    CodeBank

    Form Fading Effects in VB.NET and C#

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width