Results 1 to 6 of 6

Thread: vb.net--fading a form out or in

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2003
    Posts
    1,489

    vb.net--fading a form out or in

    to make you form fade when it loses focus or vice-versa, try this out:

    Code:
    Private Sub fclsCallsLogger_Deactivate(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Deactivate
            'this routine fades the form when it loses focus
    
            Dim x As Decimal = 0
            Do While Me.Opacity > 0.5
                Me.Refresh()
                Me.Opacity -= 0.05
                For x = 1 To 100000
                Next x
            Loop
    
        End Sub
    just change the control (fclscallslogger) to your form's name and viola'! to fade it, reverse the '>' and me.opacity -

    to make it 100% opace,:

    Code:
    Private Sub fclsCallsLogger_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Activated
            'when the form receives focus again, we must make opacity 100%
    
            Me.Opacity = 1
    
        End Sub
    Enjoy!

  2. #2
    Addicted Member Codehammer's Avatar
    Join Date
    Aug 2004
    Posts
    164

    Re: vb.net--fading a form out or in

    I Wanted to Ask, If the Form is is Minimized, then fclsCallsLogger_Deactivate is Excuted or do you have to use fclsCallsLogger_MinimumSizeChanged
    Curiosity SKILLED the cat
    Google Talk from your Mobile phone

    Chat from your mobile or get an emulator like J2ME Wireless Toolkit 2.2

  3. #3
    Junior Member
    Join Date
    Apr 2007
    Location
    Singapore
    Posts
    22

    Talking Re: vb.net--fading a form out or in

    There is a problem with that code, though. If the form gains focus again while it is fading, the whole application just jams...

    There is a simpler method, which also avoids that error.

    Create a timer. Lets call the timer "Timer_fade"
    Create a button for Exit, call it "btnExit"

    Add this:

    Code:
        Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
            Timer_fade.Enabled = True
        End Sub
    
        Private Sub Timer_fade_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer_fade.Tick
            If Me.Opacity > 0.1 Then
                Me.Opacity -= 0.015
            Else
                Me.Close()
                Timer_fade.Enabled = False
            End If
        End Sub
    Do note that that is the Fade OUT code. I'm sure you know how to do fade in with that given. If there are any questions, just reply here.

  4. #4
    New Member
    Join Date
    Apr 2011
    Posts
    2

    Re: vb.net--fading a form out or in

    Hello all. I've seen examples of this code all over the net. It doesn't work for me. I have an MDI child form with no control box, min or max buttons, and no title. It has a white background. It does not fade, it only closes after the timer expires. Anyone have a suggestion on this?

    Thanks,
    NumbLock

  5. #5
    PowerPoster JuggaloBrotha's Avatar
    Join Date
    Sep 2005
    Location
    Lansing, MI; USA
    Posts
    4,286

    Re: vb.net--fading a form out or in

    Try the one that I'd linked to in my sig: FadeGradientForm
    Currently using VS 2015 Enterprise on Win10 Enterprise x64.

    CodeBank: All ThreadsColors ComboBoxFading & Gradient FormMoveItemListBox/MoveItemListViewMultilineListBoxMenuButtonToolStripCheckBoxStart with Windows

  6. #6
    New Member
    Join Date
    Apr 2011
    Posts
    2

    Re: vb.net--fading a form out or in

    Hello. Thanks for the reply. I might be misreading your post but it looks like it is for fading an MDI Container and not an MDI Child form. Am I missing something? I must admit, I didn't go through all the code, just from the details on the page you linked.

    Thanks,

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