Visual Basic Programming

Page 10

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.

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.

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:

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

Type the following code in the cmdPrint code:

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

Type the following code in the cmdClear code:

Now lets code the rollover for cmdExit

Type the following code in the cmdExit code:

We are almost done with the coding! Now for the form. The mouse has to move on that too.

Type the following code in the Form code:

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.

Top of Page

Page 1 | Page 2 | Page 3 | Page 4 | Page 5 | Page 6 | Page 7 | Page 8 | Page 9 | Page 10 | Page 11

Page 12 | Page 13 | Page 14 | Page 15 | Page 16 | Page 17 | Page 18 | Page 19 | Page 20

Page 21 | Page 22 | Page 23 | Page 24 | Page 25 | Page 26 | Page 27 | Page 28 | Page 29 | Page 30