Contents:

Main
Tutorials
3D Control
'97 Tool Bar
Screen Saver
NotePad
y2k counter

Examples
Source Code
FAQ
Files

Microsoft

 

Make a '97 Style Toolbar

You may have noticed that the newer Microsoft products have those special toolbars, that highlight when there is a mouse over event. In VB 3 & 4 there is no control for this, so here's how to do it.

This is moderately hard to understand whats going on, but very easy to implement...so what's stopping you

This is what it'll look like The picure shows six PictureBoxes and two Lines. The Appearace property of each PictureBox is set to "0 - Flat". The Border around the pictures is set to "1 - Fixed Single" to show you the size of the pictures. This property will be set to "0 - none" in the end. The big black square where all the PictureBoxes and Lines are in is also a Picture Box. In order to get pictures, use the Capture option of programs like Paint Shop Pro. Make sure that the size of the pictures is 16 x 16 pixels with 16 colors.

Here's how you create the picture you see:
Put a PictureBox on the Form. Make it a big one. This will be the background for our toolbar.
Change the following properties:
Appearance : 0 - Flat
AutoRedraw : True
BackColor : &H8000000A&
BorderStyle : 1 - Fixed Single
Name : Picture2
ScaleMode : 3 - Pixel

Now insert another PictureBox in the other PictureBox. Set the following properties:
Appearance : 0 - Flat
AutoRedraw : True
BackColor : &H8000000A&
BorderStyle : 1 - Fixed Single
Height : 17
Name : Picture1
Picture : <-Add a pictures.->
ScaleMode : 3 - Pixel
Width : 17

Toolbar so farOn this picture you will see how it should look like. Press the right mousebutton on Picture1, so that it is selected and a popup menu appears. Select Copy in this menu. Now press the right mousebutton on Picture2. Select Paste and respond with "Yes" to the question if you want to make a control array. Do this four times, so that there will be five little pictures in the big PictureBox. Arrange them just like in the picture at the top of this page and choose for each individual PictureBox a nice picture (except for the big one of course!).

The only thing we don't have included yet are the two lines. In order to place them directly against each other you will have to uncheck the "Align Controls to Grid" option from the Tools|Options menu. Now you can simply draw two lines in the big PictureBox and arrange them correctly. The colors are: &H80000010& for the dark (left) one, and &H80000014& for the light (right) one. After this it is better to check the "Align Controls to Grid" option again.

Before I start listing the Source Code, let's see if we can think of what we need. First of all the 3D-effects of the button should become visible if you move the mousecursor over them, and it should be invisible if you move the mouse away from it.
Second, the buttons should "move" if you push them: the button should lower if you press the mousebutton and it should be normal again if you release the button.

I will start giving you the code for making the 3D-effect visible. You can copy it and paste it into the Declarations Section of your form.

Private Sub MoveMouse(ByVal bIndex As Byte)

If
bIndex <> OldIndex Then ' If it is already drawn, then don't do it again!

Dim
iX As Integer, iY As Integer

If
OldIndex <> 100 Then ' Index 100 = No button selected!
Picture2.Line
(iOldX, iOldY)-(iOldX + 17 + 8, iOldY + 17 + 8), &H8000000A, B
' Remove the 3D-effect of the old button.
End If

If
bIndex <> 100 Then

iX = Picture1(bIndex).Left - 4
iY = Picture1(bIndex).Top - 5


Picture2.Line
(iX, iY)-(iX + 17 + 8, iY + 17 + 8), &H80000014, B
Picture2.Line
(iX + 17 + 8, iY)-(iX + 17 + 8, iY + 17 + 8), &H80000010, B
Picture2.Line
(iX, iY + 17 + 8)-(iX + 17 + 8, iY + 17 + 8), &H80000010, B

iOldX = iX: iOldY = iY

End If

OldIndex = bIndex

End If
End Sub

The Hexadecimal codes for the colors are special codes for the "Button Highlight", "Button Shadow" and "Active Border" colors. Some of the variables aren't declared yet, so put the following lines in the declarations section of your form:

Private OldIndex As Byte
Private
iOldX As Integer, iOldY As Integer

If you carefully read the code some times you will understand what's happening. The main event is the drawing of the lines, and the removing of the old ones. I will now give you the other two subs required for the project. Just paste them into the declarations section.

Private Sub DownMouse(ByVal bIndex As Byte)

If
bIndex <> 100 Then

Dim
iX As Integer, iY As Integer

iX = Picture1(bIndex).Left - 4
iY = Picture1(bIndex).Top - 5

Picture2.Line
(iX, iY)-(iX + 17 + 8, iY + 17 + 8), &H80000010, B
Picture2.Line
(iX + 17 + 8, iY)-(iX + 17 + 8, iY + 17 + 8), &H80000014
Picture2.Line
(iX, iY + 17 + 8)-(iX + 17 + 8 + 1, iY + 17 + 8), &H80000014

Picture1(
bIndex).Left = iX + 5
Picture1(
bIndex).Top = iY + 6

End If
End Sub

Private Sub UpMouse(ByVal bIndex As Byte)

If
bIndex <> 100 Then

Dim
iX As Integer, iY As Integer

iX =
Picture1(bIndex).Left - 4 - 1
iY =
Picture1(bIndex).Top - 5 - 1

Picture2.Line
(iX, iY)-(iX + 17 + 8, iY + 17 + 8), &H80000014, B
Picture2.Line
(iX + 17 + 8, iY)-(iX + 17 + 8, iY + 17 + 8), &H80000010
Picture2.Line
(iX, iY + 17 + 8)-(iX + 17 + 8 + 1, iY + 17 + 8), &H80000010

Picture1(
bIndex).Left = iX + 4
Picture1(
bIndex).Top = iY + 5

End If
End Sub

We now have created the visible part and the Source Code, but still nothing works! This is because the functions (subs) are never called. This is the last thing we need to do, and it is also the easiest part. Just follow the instructions below:

Add to Form_Load:
OldIndex = 100

Add to Form_MouseMove:
Call MoveMouse(100)

Add to Picture1_DblClick:
Call DownMouse(Index)

Add to Picture1_MouseDown:
Call DownMouse(Index)

Add to Picture1_MouseMove:
If Button = 0 Then
Call
MoveMouse(Index)
End If

Add to Picture1_MouseUp:
Call UpMouse(Index)

Select Case Index
Case 0 ' First button pressed.
'Here you can insert the actions that follow on the pressing of button 0.
Case 1 ' Second button pressed.
'Here you can insert the actions that follow on the pressing of button 1.
'etc.

End Select

Add to Picture2_MouseMove:
Call MoveMouse(100)

Add to every other control's _MouseMove sub:
Call MoveMouse(100)

The last line makes sure that if you move quickly from one of the buttons to another control on the form (e.g. a TextBox), the 3D-effect will disappear from the button. Otherwise it wouldn't go away.

Well, we are almost finished now. But the BorderStyle properties of all the PictureBoxes are still on "1 - Fixed Single". You can now change them all into "0 - None". That looks much better!

The finished thing

This is what the finished thing should look like.