Show the hints in a TPanel  

Send By: Radikal (Q3 Team)
Web : http://www.q3.nu
Email: radikal@q3.nu
Date: 25/10/99

Tip accessed 668 times

 


Maybe interest you to show the hints of your components in a TPanel or in a status bar.
It is easy, it's enough with use the Application.OnHint event

Here you have an example:

  • Put a TPanel (Panel1) and two TButtons in your form
  • Put something in the Hint properties of the TButtons (to test the invention)
  • Put the ShowHint property of the TButtons to FALSE
  • Put this declaration in the private part of your form:


       private
         { Private declarations }
         procedure OtroHint (Sender:TObject);
    



  • Now, put the function in the implementation part:


     procedure TForm1.OtroHint(Sender:TObject);
     begin
       Panel1.Caption:=Application.Hint;
     end;
    



  • Now, we must assign our procedure to the Application.OnShowHint event. We will make this in the OnCreate event of the form:


     procedure TForm1.FormCreate(Sender: TObject);
     begin
       Application.OnShowHint:=OtroHint;
     end;
    





    An user of Trucomania, wondered about the possibility of knowing when he takes place and when of a Hint it erases, with the purpose of making that the hint shown in the TPanel doesn't remain fixed, but rather it works as the normal hints, that is to say that they appear and to that of a time they disappear.
    For it, I am happened... to use the method Application.OnShowHint in place the OnHint, showing the hint in the Panel, and activating a timer so that it erases it in the preset time.

    Here you have a example of this:

  • Put a TPanel (Panel1), a TTimer (Timer1) and two TButtons in your form
  • Put something in the Hint properties of the TButtons (to test the invention)
  • Put the ShowHint property of the TButtons to TRUE
  • Put this declaration in the private part of your form:


     private
       { Private declarations }
       procedure MiHint(var HintStr: string; var CanShow: Boolean; var HintInfo: THintInfo);
    



  • Now, put the function in the implementation part:


     procedure TForm1.MiHint(var HintStr: string; var CanShow: Boolean; var HintInfo: THintInfo);
     begin
       {Don't show the hint over the control}
       CanShow :=FALSE;
       {Get Hint string}
       Panel1.Caption:=HintInfo.HintStr;
       {Set Hint-Hide Time}
       Timer1.Interval:=HintInfo.HideTimeout;
       {Re-Start timer}
       Timer1.Enabled:=FALSE;
       Timer1.Enabled:=TRUE;
     end;
    



  • Now, we must assign our procedure to the Application.OnShowHint event. We will make this in the OnCreate event of the form:


     procedure TForm1.FormCreate(Sender: TObject);
     begin
       Application.OnShowHint:=MiHint;
     end;
    



  • to finish, we put this code in the OnTimer event of Timer1, to erase the hint when its time has expired:


     procedure TForm1.Timer1Timer(Sender: TObject);
     begin
       Panel1.Caption:='';
       Timer1.Enabled:=FALSE;
     end;