BooksXL - Your Online Bookshop

 

Home

Projekte

VB Tipps

über mich

vb tipps

 

 

home go to german version

Tooltips with Visual Basic (VB3)

 

like so many of these stories from programing it starts in long, dark and cold night. The customer wanted to see tooltips - the program was for Windows 3.x, we had the time of VB3 and Tooltips were unknown features. Tooltips are the small yellow flyers appearing when you rest over an icon. And they are for these guys of us that had to learn reading in school. BTW, a friend of mine told me, he saw a plane used as an icon .-o any suggestions? There we know why to show tooltips. No problem, let us use F1 and the documentation?

First: VB Documentation / Help

Let's skip the code. The documentation tells us to enable a timer when coming to the button (MouseMove). About 1 second later it fires and shows us the yellow text box. The surrounding Window (the button bar) also uses MouseMove to hide the yellow box.

Very nice. But test the following: If you are fast enough  leaving the toolbar with your mouse pointer (race mouse >= 0.02m/s), the yellow box will still be shown. Some guys have slower mice; they leave the button by the shown Tooltip and use it as a bridge over the surrounding window. So ..

2nd Version: MS Developer Network

In former times when there was no MSDN Online, you had to spend some bucks for the CDs. But there a solution seemed to be found:
Timer enables as before. When it fires, the focus is set to the button. Then the button gets any event on the form. In it's MouseOver event the button asks whether the pointer position is inside or outside the button area. When outside it hides the Tooltip, disables the timer and gives focus back th the system.

Much better. I needed some testing to see, this is not to bad. But it was just half the way if you try to use this solution with a collection of buttons. Press down the mouse button, leave the button and move over your application: Any button from the collection will flip down when he sees your mouse pointer.

Last Version: Do It Yourself again

OK, the 2nd version was not to bad. But of course, you should not take focus away from the button when you leave it while your mouse is predded. The button has to recognize a MouseUp event (=MouseClick) and he has to be pressed when you come back.

Private Sub ribBereich_MouseDown(Index As Integer, _
Button As Integer, Shift As Integer, X As Single, Y As Single) MouseIsDown = True End Sub Private Sub ribBereich_MouseMove(Index As Integer, _
Button As Integer, Shift As Integer, X As Single, Y As Single) ' if user moved off button... If X > ribBereich(Index).Width Or X < 0 Or
Y > ribBereich(Index).Height Or Y < 0 Then ' turn off timer tmrButtons.Enabled = False If MouseIsDown = False Then ReleaseCapture End If ' hide the help lblButtonInfoTip.Visible = False Else If Not lblButtonInfoTip.Visible Then gnQuickInfoButtonSelected = Index tmrButtons.Enabled = True Dim i As Integer i = SetCapture(ribBereich(Index).hWnd) End If End If End Sub Private Sub ribBereich_Click(Index As Integer, Value As Integer) Dim i As Integer MouseIsDown = False If lblButtonInfoTip.Visible = True Then frmKRegion.tmrButtons.Enabled = False lblButtonInfoTip.Visible = False ReleaseCapture End If ... End Sub Private Sub ribBereich_MouseUp(Index As Integer, _
Button As Integer, Shift As Integer, X As Single, Y As Single) MouseIsDown = False End Sub

So we have to add 2 simple things: Any button gets it's variable to hold wether mouse is down or not. And the button keeps the focus when mouse is pressed and the pointer leaves the button area, it just hides it's tooltip.

 

top