[Lazarus] RE : Multiple hints for a TStatusBar
Ludo Brands
ludo.brands at free.fr
Sat May 19 11:07:08 CEST 2012
> Please don't put significant thought into this, but does
> anybody have a
> reliable code fragment that will pop up a different hint from a
> multi-panel status bar, depending on which panel the mouse is over?
>
Create an OnMouseMove event handler for the status bar and use the following
code:
procedure TForm1.StatusBar1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
var
i,border:integer;
begin
i:=0;
border:=0;
repeat
border:=border+StatusBar1.Panels[i].Width;
i:=i+1;
until (i=StatusBar1.Panels.Count) or (X<border);
StatusBar1.Hint:='Panel '+IntToStr(i);
application.CancelHint;
application.ActivateHint(mouse.CursorPos);
end;
This will show a hint 'Panel 1', 'Panel 2', etc. when you hover over the
different panels. Replace StatusBar1.Hint:='Panel '+IntToStr(i); with
whatever code to display the hint you like.
The block
application.CancelHint;
application.ActivateHint(mouse.CursorPos);
is needed to cancel and retrigger the hint whenever the mouse moves. The
Statusbar is one control and moving the mouse from one panel to another
without exiting the status bar wouldn't cancel and retrigger the hint.
Tested on windows.
Ludo
More information about the Lazarus
mailing list