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!
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
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. :)
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
Re: vb.net--fading a form out or in
Try the one that I'd linked to in my sig: FadeGradientForm
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,