As I mentioned on Page 7, I will now teach you to do Rollovers with the Organic Oranges interface. If you did not save it as I mentioned on Page 7, you are out of luck! I guess you will just have to re-create the program. But hopefully, you saw the note at the end of Page 7. So lets begin.
There is no mouse over event in Visual Basic, so how are we going to do this? Simple. We can use the mousemove event. The event occurs when the mouse moves on a specified object. The reason you needed to learn If Then statements first is because a rollover in Visual Basic requires ALL If Then statements. Think of it this way. The mousemove event happens every time the mouse moves. With most users, that is very often. Suppose we just set the color to a button in the mousemove event without the If Then statement. Well, lets see what happens.
First, set each command button's Style property to Graphical.
This allows the command buttons to be more graphical as the property shows. Now the button can display a BackColor. Because this is an order for oranges, I find it appropriate to use an orange color.
Make sure that the BackColor property is set to &H8000000F& for all command buttons. Be careful. Sometimes the initial button color is different than this one. Make sure.
Double click the cmdCalc button to open the code window.
Select the MouseMove event in the code window's event box.
Type the following code:
cmdCalc.BackColor = &H80C0FF
The code above states that the BackColor of cmdCalc is equal to &H80C0FF. Therefore, each time the mouse moves on cmdCalc, the color will change as specified. This refreshes the color on the button multiple times. Try running the program if you'd like.
So now, lets fix this.
Type the following code in the cmdCalc code:
If cmdCalc.BackColor = &H8000000F Then cmdCalc.BackColor = &H80C0FF
If cmdPrint.BackColor = &H80C0FF Then cmdPrint.BackColor = &H8000000F
Be sure that you erase the other code that we just entered as well. The code above simply states that If the back color (button's color) of cmdCalc is &H8000000F, change it (cmdCalc) to &H80C0FF. The next line simply say that If the cmdPrint objects back color is &H80C0FF, change it (cmdPrint) to &H8000000F. Remember that the objects are very close to each other, so the mouse will probably touch the buttons before the form, which we will code in a bit.
Now lets code the rollover for cmdPrint
Select the MouseMove event in the code window's event box for cmdPrint.
Type the following code in the cmdPrint code:
If cmdCalc.BackColor = &H80C0FF Then cmdCalc.BackColor = &H8000000F
If cmdClear.BackColor = &H80C0FF Then cmdClear.BackColor = &H8000000F
If cmdPrint.BackColor = &H8000000F Then cmdPrint.BackColor = &H80C0FF
Line 1: Sets the cmdCalc BackColor property back to &H8000000F
if it was &H80C0FF when the mouse leaves
Line 2: Sets the cmdClear BackColor property back to &H8000000F if it was &H80C0FF
when the mouse leaves
Line 3: Sets the cmdPrint BackColor property back to &H80C0FF if it was &H8000000F
when the mouse moves on it
Basically, the color needs to change when the mouse moves on it. The colors should change each time the mouse is on the button and when it leaves. Each button needs to test the color of the button the mouse left, but not change it all the time. Otherwise, the button will flicker with each mouse move. I hope that clears it a little.
Now lets code the rollover for cmdClear
Select the MouseMove event in the code window's event box for cmdClear
Type the following code in the cmdClear code:
If cmdPrint.BackColor = &H80C0FF Then cmdPrint.BackColor = &H8000000F
If cmdExit.BackColor = &H80C0FF Then cmdExit.BackColor = &H8000000F
If cmdClear.BackColor = &H8000000F Then cmdClear.BackColor = &H80C0FF
Now lets code the rollover for cmdExit
Select the MouseMove event in the code window's event box for cmdExit
Type the following code in the cmdExit code:
If cmdClear.BackColor = &H80C0FF Then cmdClear.BackColor = &H8000000F
If cmdExit.BackColor = &H8000000F Then cmdExit.BackColor = &H80C0FF
We are almost done with the coding! Now for the form. The mouse has to move on that too.
Select the Form object in the code window's object box.
Select the MouseMove event in the code window's event box for the form
Type the following code in the Form code:
If cmdCalc.BackColor = &H80C0FF Then cmdCalc.BackColor = &H8000000F
If cmdPrint.BackColor = &H80C0FF Then cmdPrint.BackColor = &H8000000F
If cmdClear.BackColor = &H80C0FF Then cmdClear.BackColor = &H8000000F
If cmdExit.BackColor = &H80C0FF Then cmdExit.BackColor = &H8000000F
Now all the rollovers should work just dandy!
Hope you enjoyed this tedious practice with rollovers. Now I will teach you If Then statements using variables on Page 11.