Delphi : Prevent TPageControl Hint from showing on contained items
Question
I have a form with the following components: A TPageControl
containing a single TTabSheet
, containing a TEdit
.
I want a hint "Hello" displayed when I mouse over the pagecontrol tab, and no hint displayed when I mouse over the TEdit.
The PageControl
has a hint= "Hello"
, and showhint = true
. This works as expected.
The TEdit
has showhint = false
, parentshowhint = false
, and hint
is empty.
But, I still get a "Hello" hint whn I mouseover the TEdit. How can I stop this?
Here's the .dfm, if you're interested.
object Form65: TForm65
Left = 0
Top = 0
Caption = 'Form65'
ClientHeight = 258
ClientWidth = 290
OldCreateOrder = False
ShowHint = True
TextHeight = 13
object PageControl1: TPageControl
Left = 0
Top = 0
Width = 290
Height = 258
Hint = 'Bar'
ActivePage = TabSheet1
Align = alClient
TabOrder = 0
object TabSheet1: TTabSheet
Caption = 'TabSheet1'
object Edit3: TEdit
Left = 72
Top = 67
Width = 121
Height = 21
ParentShowHint = False
ShowHint = False
TabOrder = 0
Text = 'tab1'
end
end
end
end
Solution
Add a TApplicationEvents control to your form, and use the OnShowHint event:
procedure TForm1.ApplicationEvents1ShowHint(var HintStr: string;
var CanShow: Boolean; var HintInfo: THintInfo);
begin
CanShow := HintInfo.HintControl <> Edit1;
end;
If you do not have the TApplicationEvents object in (e.g. if you are using a very old version of Delphi), then you can use (in FormCreate, for instance)
Application.OnShowHint := ApplicationEvents1ShowHint
to set the event handler manually.
Update
If you have more than one control in the TTabSheet, then you might have the same problem with them all. Then you might be interested in
procedure TForm1.ApplicationEvents1ShowHint(var HintStr: string;
var CanShow: Boolean; var HintInfo: THintInfo);
begin
CanShow := not SameStr(HintStr, PageControl1.Hint) or (HintInfo.HintControl = TabSheet1);
end;
Update 2
If you have several TTabSheets in the TPageControl, and want all sheets to display the hint, but non of the child controls, then you can do
CanShow := not SameStr(HintStr, PageControl1.Hint) or
((HintInfo.HintControl is TTabSheet) and
(TTabSheet(HintInfo.HintControl).PageControl = PageControl1));
instead.