Recent

Author Topic: Questions about the OnShowHint events in TtoolBar and ToolButtons  (Read 469 times)

jamie

  • Hero Member
  • *****
  • Posts: 5043
I know that I can implement the Application.OnShowHint to intercept all hints and do any modifications if needed. How about the OnShowHint that lives in the TControl of most controls?

  Currently I am working with a TtoolBar and it sits above an active area where I really would like the HINT not to show when I rest over any of its TtoolButtons.

 I would like to intercept the TtoolButton OnShowHint or maybe even just the OnShowHint of the Tool bar when any of the buttons needs to show the hint.

  Does the OnShowHint of the TtoolBar trigger for any of its TtoolButtons ?
The only true wisdom is knowing you know nothing

dsiders

  • Hero Member
  • *****
  • Posts: 748
Re: Questions about the OnShowHint events in TtoolBar and ToolButtons
« Reply #1 on: November 15, 2022, 01:31:30 am »
I know that I can implement the Application.OnShowHint to intercept all hints and do any modifications if needed. How about the OnShowHint that lives in the TControl of most controls?

  Currently I am working with a TtoolBar and it sits above an active area where I really would like the HINT not to show when I rest over any of its TtoolButtons.

For that, all you need is:

Code: Pascal  [Select][+][-]
  1. ToolBar1.ShowHint := False;

I would like to intercept the TtoolButton OnShowHint or maybe even just the OnShowHint of the Tool bar when any of the buttons needs to show the hint.

  Does the OnShowHint of the TtoolBar trigger for any of its TtoolButtons ?

I don't see anything beyond the support provided for CM_HINTSHOW in TControl. That signals OnShowHint when assigned. But neither TToolBar nor TToolButton publish the OnShowHint event. Why? Probably because Delphi doesn't.

OnShowHint is public in TControl, so you can assign a routine at run-time.  I think TToolBar is the logical choice since it already handles ShowHint and ShowCaption for its buttons.

To be honest, I've never had the need to tweak hints... anywhere.


Preview Lazarus 2.3.0 documentation at: https://dsiders.gitlab.io/lazdocsnext

jamie

  • Hero Member
  • *****
  • Posts: 5043
Re: Questions about the OnShowHint events in TtoolBar and ToolButtons
« Reply #2 on: November 15, 2022, 03:08:03 am »
Hmm.

 Maybe I didn't explain well enough.
   
  I don't want to know when to disable it, I want to be able to intercept it logically to recalculate the position of the popup message so that it still displays but in a different location, so it does not cover the active area. Example, above the Tool bar button instead of the bottom.

  Of course, I would need to ensure there is space up there and if not then allow it to show where it can at the moment.


  I fine it interesting that there is no OnShowHint published event that can capture this via the toolbar controls etc.

  If you study the information provided in that event, it will allow you to do just about anything you want with that message before it displays.


The only true wisdom is knowing you know nothing

jamie

  • Hero Member
  • *****
  • Posts: 5043
Re: Questions about the OnShowHint events in TtoolBar and ToolButtons
« Reply #3 on: November 15, 2022, 05:14:22 pm »
Ok, I've come up with a block of test code that seems to not be too painful to implement.

 The real code will be applied to the buttons on the Toolbar and can set the OnShowHint event to point to a single handler.
Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormCreate(Sender: TObject);
  2. begin
  3.   Button1.OnShowHint := @Self.ProcessHint;
  4. end;
  5.  
  6. procedure Tform1.ProcessHint(Sender:TObject; HintInfo:PhintInfo);
  7. Begin
  8.   With HintInfo^ do
  9.   Begin
  10.     HintPos := HintControl.ControlToScreen(Point(10,-CurSorRect.Height));
  11.   end;
  12. End;                              
  13.  

Like I said, this is just test code for now and the object of what I am trying to do is avoid the hint message to overlay active area that are just below.

 have a good day.
The only true wisdom is knowing you know nothing

dsiders

  • Hero Member
  • *****
  • Posts: 748
Re: Questions about the OnShowHint events in TtoolBar and ToolButtons
« Reply #4 on: November 15, 2022, 08:19:46 pm »
Ok, I've come up with a block of test code that seems to not be too painful to implement.

 The real code will be applied to the buttons on the Toolbar and can set the OnShowHint event to point to a single handler.
Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormCreate(Sender: TObject);
  2. begin
  3.   Button1.OnShowHint := @Self.ProcessHint;
  4. end;
  5.  
  6. procedure Tform1.ProcessHint(Sender:TObject; HintInfo:PhintInfo);
  7. Begin
  8.   With HintInfo^ do
  9.   Begin
  10.     HintPos := HintControl.ControlToScreen(Point(10,-CurSorRect.Height));
  11.   end;
  12. End;                              
  13.  

Like I said, this is just test code for now and the object of what I am trying to do is avoid the hint message to overlay active area that are just below.

 have a good day.

Interesting.

It assumes the hint is in the control you're trying to avoid though. Perhaps the control rectangle and the hint rectangle do not overlap.

IAC, thanks for the follow up.
Preview Lazarus 2.3.0 documentation at: https://dsiders.gitlab.io/lazdocsnext

jamie

  • Hero Member
  • *****
  • Posts: 5043
Re: Questions about the OnShowHint events in TtoolBar and ToolButtons
« Reply #5 on: November 15, 2022, 09:36:17 pm »
While in the process of doing this I have found that using a

FOR ACONTROL in TOOLBAR Do...

Only finds TToolbutton controls but not any other controls living on the bar

So, I had to do it the old school way to locate the controls when setting their OnShowHint events

 I have speed buttons there also but are not seen using the Enumerator method
The only true wisdom is knowing you know nothing

dsiders

  • Hero Member
  • *****
  • Posts: 748
Re: Questions about the OnShowHint events in TtoolBar and ToolButtons
« Reply #6 on: November 15, 2022, 10:09:45 pm »
While in the process of doing this I have found that using a

FOR ACONTROL in TOOLBAR Do...

Only finds TToolbutton controls but not any other controls living on the bar

So, I had to do it the old school way to locate the controls when setting their OnShowHint events

 I have speed buttons there also but are not seen using the Enumerator method

I think TControlBar is the one intended for use with controls.
Preview Lazarus 2.3.0 documentation at: https://dsiders.gitlab.io/lazdocsnext

wp

  • Hero Member
  • *****
  • Posts: 10454
Re: Questions about the OnShowHint events in TtoolBar and ToolButtons
« Reply #7 on: November 15, 2022, 10:55:11 pm »
While in the process of doing this I have found that using a

FOR ACONTROL in TOOLBAR Do...

Only finds TToolbutton controls but not any other controls living on the bar
Iterate yourself over the Controls[ i] of the Toolbar by using a plain old-fashioned "for i" loop:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. var
  3.   s: String = '';
  4.   i: Integer;
  5. begin
  6.   for i := 0 to Toolbar1.ControlCount-1 do
  7.     s := s + ';' + Toolbar1.Controls[i].Name;
  8.   Delete(s, 1, 1);
  9.   ShowMessage(s);
  10. end;

 

TinyPortal © 2005-2018