Hey guys. Today I'm gonna show you one of the coolest things you can use in your forms. Ever created a toolbox (a form that has tools or lots of buttons, like an on-screen keyboard, for example) but wished it would disappear when you don't need it? You probably don't, but I'm gonna show you anyway.
This is a little something I did in my spare time. It took me a while, but the end code turned out to be relatively simple. I'm only new to VB (only a student still

) and I would eventually like to work into more advanced languages.
So here's what you need:
- A form (any size, shape, colour..It doesn't matter..It's your choice!)
- A timer (Enabled, Interval is 10 milliseconds)
That's it. Just to clear things up, I'm using 10 milliseconds because it doesn't lag the fading. You can put it at 1 if you like but for now, I'm just going to use 10.
Anyways, let's start with the code.
CODE
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
If (MousePosition.X - (Me.Location.X + Me.Width)) > 33 Then
Me.Opacity -= 0.03
ElseIf (MousePosition.Y - (Me.Location.Y + Me.Height)) < -(Me.Bounds.Height + 33) Then
Me.Opacity -= 0.03
ElseIf (MousePosition.X - (Me.Location.X + Me.Width)) < -(Me.Bounds.Width + 33) Then
Me.Opacity -= 0.03
ElseIf (MousePosition.Y - (Me.Location.Y + Me.Height)) > 33 Then
Me.Opacity -= 0.03
Else
Me.Opacity += 0.03
End If
Ok, let me break it down for you:
CODE
If (MousePosition.X - (Me.Location.X + Me.Width)) > 33 Then
Me.Opacity -= 0.03
Basically, this tells us if the user has his mouse too far right from the form, the form will fade away by reducing the opacity by 0.03 (which is equal to 3%) every interval (10ms). This means it takes a grand total of 30 intervals (or 300ms) for the form to fully disappear. You can change this number to suit your design. If you want it to appear/reappear quickly, you can try 0.1 or 0.2 (which equals 10% and 20% respectively) and so on..
CODE
ElseIf (MousePosition.Y - (Me.Location.Y + Me.Height)) < -(Me.Bounds.Height + 33) Then
Me.Opacity -= 0.03
This tells us that if the user is too high above the form, the form will fade away.
CODE
ElseIf (MousePosition.X - (Me.Location.X + Me.Width)) < -(Me.Bounds.Width + 33) Then
Me.Opacity -= 0.03
Again, this tells us if the user is too far to the left of the form, and the form will fade away.
CODE
ElseIf (MousePosition.Y - (Me.Location.Y + Me.Height)) > 33 Then
Me.Opacity -= 0.03
You probably got the hang of this...This tells us if the user is too far below the form, and the form will (of course) fade away.
CODE
Else
Me.Opacity += 0.03
End If
And finally, if all of the above fail (which means the user is within reach of the form), the form will reappear again.
If you notice in my code, the 33's are there because they are the distance from which the user has to be in from the form to actually appear. For example, the user has to be at least 33 pixels away from the top edge of the form for the form to appear. Feel free to change the 33's to any number you like. If you want your user to have to get real close to the form for it to appear, you could put 10 or even 5. But if you want the form to appear from a further distance, you could put 100. It's really up to you.
Here's a little
OPTIONAL addition to your program. This code basically says that if you at any point hold down the space bar, the form will appear instantly. This could be handy if your user can't find the form. Again, this part is optional.
CODE
Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
If e.KeyCode() = Keys.Space Then
Me.Opacity() = 1
Timer1.Stop()
Else
'Do Nothing
End If
End Sub
Private Sub Form1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyUp
Timer1.Start()
End Sub
You can change the key to be anything. Notice that I turned off the timer when the key is pressed and turned it on when it is not, that's because if I didn't it would interact with the form and make it pulse. (fade out then instantly fade in repeatedly)
I hope you learned something new today, and remember me when you are using this technique

Comments and suggestions are greatly appreciated.
Thanks and have a great day!
-remorseless