Author: Jonas Bilinkevicius
When the HotTrack property of a TPageControl is True the tabsheet captions light
blue for example when the mouse hovers over them. How can I display the TabSheets
hint when this event occurs (the TabSheet hint should be displayed only when the
mouse hovers over the TabSheet caption)?
Answer:
Use the pagecontrol's OnMouseMove event:
1 2 {tabindex may be <> pageindex if some pages have tabvisible = false!}3 4 function FindPageforTabIndex(pagecontrol: TPageControl; tabindex: Integer):
5 TTabSheet;
6 var7 i: Integer;
8 begin9 Assert(Assigned(pagecontrol));
10 Assert((tabindex >= 0) and (tabindex < pagecontrol.pagecount));
11 Result := nil;
12 for i := 0 to pagecontrol.pagecount - 1 do13 if pagecontrol.pages[i].tabVisible then14 begin15 Dec(tabindex);
16 if tabindex < 0 then17 begin18 result := pagecontrol.pages[i];
19 break;
20 end;
21 end;
22 end;
23 24 function HintForTab(pc: TPageControl; tabindex: Integer): string;
25 var26 tabsheet: TTabsheet;
27 begin28 tabsheet := FindPageforTabIndex(pc, tabindex);
29 if assigned(tabsheet) then30 result := tabsheet.hint
31 else32 result := '';
33 end;
34 35 procedure TForm1.PageControl1MouseMove(Sender: TObject; Shift: TShiftState; X, Y:
36 Integer);
37 var38 tabindex: Integer;
39 pc: TPageControl;
40 newhint: string;
41 begin42 pc := Sender as TPageControl;
43 tabindex := pc.IndexOfTabAt(X, Y);
44 if tabindex >= 0 then45 begin46 newhint := HintForTab(pc, tabindex);
47 if newhint <> pc.Hint then48 begin49 pc.Hint := newhint;
50 application.CancelHint;
51 end;
52 end53 else54 pc.Hint := '';
55 end;
56 57 {Attach this to every tabsheets OnMouseMove event}58 59 procedure TForm1.TabSheetMouseMove(Sender: TObject; Shift: TShiftState; X, Y:
60 Integer);
61 begin62 pagecontrol1.Hint := '';
63 end;