views:

579

answers:

3

I want a TPageControl and some TTabSheets, with 'per tabsheet' tooltip hints visible as I hover over each tab in turn.

Is there any way of getting this effect in Delphi 2009?

+1  A: 

1 - fill in the .Hint property, and set the .ShowHint property to True for the PageControl (assuming each tabsheet has ParentShowHint set to true; otherwise you'll have to set each page individually).

2 - Assign this event to the PageControl's OnChange event handler:

procedure TForm1.PageControl1Change(Sender: TObject);
begin
  PageControl1.Hint := PageControl1.ActivePage.Hint;
end;

After you do that, the hint will be whatever the active tab is. I am not sure how to make it change the hint based on where the mouse is hovering - that's an interesting phenomenon I've never noticed before, actually.

JosephStyons
+3  A: 

Just hook the Page Control's Mouse Move event and use the TabAtPos property to determine which tab the mouse is hovering over. Then assign that tab's Hint to the Page Control's hint property.

procedure TForm.PageControlMouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
var
  tabindex: Integer;
begin
  tabindex := PageControl.IndexOfTabAt( X, Y );
  if tabindex >= 0 then
     PageControl.Hint:=PageControl.Pages[tabindex].Hint
end;
Gerard
TabAtPos doesn't exist, you meant IndexOfTabAt(x,Y).This *so* nearly works right. Except that as you move from one tab to another, the hint doesn't update or re-show.
Roddy
Apologies; I was using TRzTabSheet (Raize Components) which has a TabAtPos property and works well. You could just programmatically show the hint on a change of tabindex using the THintWindow class. Set the Page Control's Show Hint property to false and create your own.
Gerard
+3  A: 

In Raize Components, this can be accomplished by setting the trzpagecontrol.tabhints property to true. Good components can save you a lot of time (therefore money).

(just a happy customer, btw)

Argalatyr
+1 - The investment in Raize components is well worth it. The support is world class, and the visual style options can really set your application apart from others using standard controls.
skamradt
Agreed. We use Raize almost exclusively for all UI design work. Great components and good support.
Gerard