Microsoft KB Archive/152259

= How To Sync the StatusBar Text with the ToolTip Text =

Article ID: 152259

Article Last Modified on 8/30/2004

-

APPLIES TO


 * Microsoft Visual Basic 5.0 Learning Edition
 * Microsoft Visual Basic 6.0 Learning Edition
 * Microsoft Visual Basic 5.0 Professional Edition
 * Microsoft Visual Basic 6.0 Professional Edition
 * Microsoft Visual Basic 5.0 Enterprise Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition
 * Microsoft Visual Basic 4.0 Standard Edition
 * Microsoft Visual Basic 4.0 Professional Edition
 * Microsoft Visual Basic 4.0 32-Bit Enterprise Edition

-



This article was previously published under Q152259



SUMMARY
The Microsoft Windows Common Controls OCX (COMCTL32.OCX) provides a ToolBar control and a StatusBar control that you can easily implement in your Visual Basic application. There is no built-in method to synchronize these two controls such that the StatusBar displays descriptive text for a ToolBar button when the mouse is currently located over it. This article illustrates how you can implement this behavior within your Visual Basic application.



MORE INFORMATION
Some applications, such as Microsoft PowerPoint, Word, and Excel, will not only display a helpful tip when the mouse hovers over a ToolBar button, but will also display more descriptive text in the StatusBar to give the user a definition of the button's function. Although this feature is not built into the Toolbar and StatusBar controls in COMCTL32.OCX, there are ways to mimic its effect in a Visual Basic application as described in the following sample.

Steps to Create Sample
 Create a new Visual Basic project. Form1 is created by default. Select Components from the Projects menu, check "Microsoft Windows Common Controls" and Click OK. Add a ToolBar control to Form1. Add a StatusBar control to Form1. Insert two buttons on the ToolBar by right-clicking the ToolBar control, selecting "Properties," and then the selecting the Buttons Tab.  For the first button, Click "Insert Button" and set these properties:   Property         Value -  Tag              Opens a File ToolTipText     Open

</li>  For the second button, Click "Insert Button" and set these properties: <pre class="fixed_text">  Property         Value -  Tag              Closes a File ToolTipText     Close

</li> Right-click the StatusBar control and click Properties. Click the Panels tab and set the AutoSize property of the first panel to "1-sbrSpring."</li>  Paste the following code into Form1's code window: Private Sub Form_MouseMove(Button As Integer, _        Shift As Integer, X As Single, Y As Single) StatusBar1.Panels(1).Text = "" ' Clear when not over ToolBar End Sub

Private Sub Toolbar1_MouseMove(Button As Integer, _        Shift As Integer, x As Single, y As Single)

Dim Found As Boolean Dim ToolBarButton As Variant Dim Index As Long

'Loop through all buttons on the toolbar For Index = 1 To Toolbar1.Buttons.Count 'Set reference to button Set ToolBarButton = Toolbar1.Buttons(Index)

'Check if mouse is positioned over button If (x > ToolBarButton.Left) And _ (x < (ToolBarButton.Left + ToolBarButton.Width)) And _ (y > ToolBarButton.Top) And _ (y < (ToolBarButton.Top + ToolBarButton.Height)) Then

'Mouse is over button. Now to avoid screen flickering, 'check if StatusBar needs updating If StatusBar1.Panels(1).Text <> ToolBarButton.Tag Then StatusBar1.Panels(1).Text = ToolBarButton.Tag End If

'Set flag indicating a button was found Found = True

'Button has been found, discontinue loop Exit For End If        Next

If Not Found Then StatusBar1.Panels(1).Text = "" End If     End Sub

</li> Save and run the sample project. Move the mouse over the two buttons on the ToolBar, and note that the appropriate text will be displayed in the StatusBar's panel depending on which button, if any, the mouse is positioned over.</li></ol>

Additional query words: kbDSupport kbDSD kbCtrl kbVBp500 kbVBp400 kbVBp600 kbVBp

Keywords: kbhowto KB152259

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.