VB.NET School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

 

Code Snippets

  

VB.NET Source Code


Welcome to Dream.In.Code
Become a VB.NET Expert!

Join 340,049 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 4,514 people online right now. Registration is fast and FREE... Join Now!




Fade the form in on MouseEnter and Fade out on MouseLeave

Insipired from the popular Paint .NET Graphics tool.

Submitted By: RodgerB
Actions:
Rating:
Views: 3,436

Language: VB.NET

Last Modified: January 1, 1970
Instructions: 1) Copy and Paste this code into your Form's Class.

2) Adjust the code to your likings. (Use other forms, etc).

Snippet


  1. Private Const fadeSpeed As Integer = 10 ' Controls the fade speed (Milliseconds for every change of opacity)
  2. Dim WithEvents tmrFade As New Timer() ' Our timer control.
  3. Dim fadeDirection As Boolean = False ' Boolean value of whether we want to fade up or down.
  4.  
  5. ''' <summary>
  6. ''' Timer used to fade the form.
  7. ''' </summary>
  8. ''' <remarks>
  9. ''' fadeDirection is used to determine whether the timer should be incrementing or decrementing
  10. ''' the Opacity of the Form.
  11. ''' </remarks>
  12. Private Sub tmrFade_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles tmrFade.Tick
  13.     If fadeDirection Then ' If we are incrementing the opacity
  14.         If Me.Opacity <= 1.0 Then ' If the opacity is less than 100%
  15.            Me.Opacity += 0.01 ' Increment Opacity by 1%
  16.            Exit Sub ' Exit the Subroutine to avoid Disabling the Timer.
  17.         End If
  18.     Else ' If we are decrementing the opacity
  19.         If Me.Opacity >= 0.5 Then ' If the opacity is more than 50%
  20.             Me.Opacity -= 0.01 ' Decrement Opacity by 1%
  21.             Exit Sub ' Exit the Subroutine to avoid Disabling the Timer.
  22.         End If
  23.     End If
  24.     ' Disable the timer as it doesn't fit into any of the conditions above.
  25.     tmrFade.Enabled = False
  26. End Sub
  27.  
  28. Private Sub Form1_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.MouseEnter
  29.     ' Tell the timer, that we want to fade up.
  30.     fadeDirection = True
  31.  
  32.     ' Initialise the timer.
  33.     tmrFade.Interval = fadeSpeed
  34.     tmrFade.Enabled = True
  35. End Sub
  36.  
  37. Private Sub Form1_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.MouseLeave
  38.     ' Tell the timer, that we want to fade down.
  39.     fadeDirection = False
  40.  
  41.     ' Initialise the timer
  42.     tmrFade.Interval = fadeSpeed
  43.     tmrFade.Enabled = True
  44. End Sub

Copy & Paste


Comments

preacher1 2008-07-06 17:32:09

Hi, thank you for the code snippet Roger. I am incorporating it in my amortization program for class. I did alter the fade from 0.5 to 0.8 so that my user can still see the radio buttons, button controls and output. It would be interesting to adapt the mouseover to allow the background color to change from blue or whatever color to others gradually or set by a timer so that the webpage is every changing. Tom Preacher1

APag96 2009-01-28 02:20:06

Wow. This is really cool. I was surprised on how neat it made a simple form look. Good job!

shahi300 2009-02-03 11:01:22

thank you

Asscotte 2009-04-15 06:40:20

auwsome that is sooooo cool lol :) thx

Nikhil_07n 2009-05-06 02:25:30

Nice...Thanks!

marxman89 2009-08-19 05:10:43

superb.

arkerio 2010-01-17 00:50:15

AWESOME bro NYC WORK :)


Add comment


You must be registered and logged on to </dream.in.code> to leave comments.





Live VB.NET Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month