-
With a Tabontrol, how can I assign each tab a different tooltip?
-
Why not. Pages[0].Hint := '000000'; Pages[1].Hint := '11111111';
-
I tried Pages[x].Hint.Text := 'xxx' but that gives the main tab body the tooltip - I want the tab header to have a tooltip. Is that possible? Also, how can I obtain which tab a control is placed on?
program TabTest;
uses
Windows, Messages, KOL;
var
TabControl: PControl;
i: Integer;
procedure EditboxChange(Dummy: Pointer; Sender: PControl);
begin
Sender.Parent.Caption := Sender.Caption; Sender.Parent.Hint.Text := Sender.Caption;
end;
begin
Applet := NewForm(nil, '');
TabControl := NewTabControl(Applet, [], [], nil, 0).SetAlign(caClient);
for i := 0 to 9 do
with NewEditbox(TabControl.TC_Insert(i, Int2Str(i), 0), [])^ do
OnChange := TOnEvent(MakeMethod(nil, @EditboxChange));
Run(Applet);
end.
I cannot use TabControl.CurIndex because some tabs have controls which update independently.
-
I was able to make a workaround for the VCL, but KOL has problems The KOL tooltips are correct but they constantly flash and update. Can someone please test and let me know if there is a way to stabilise the hints:
program TabTest;
uses
Windows, Messages, KOL;
var
TabControl: PControl;
i: Integer;
procedure MouseMove(Dummy: Pointer; Sender: PControl; var Mouse: TMouseEventData);
var
TabIndex: Integer;
begin
TabIndex := TabControl.TC_TabAtPos(Mouse.X, Mouse.Y);
if TabIndex >= 0 then
TabControl.Hint.Text := Int2Str(TabIndex);
end;
begin
Applet := NewForm(nil, '');
TabControl := NewTabControl(Applet, [], [], nil, 0).SetAlign(caClient);
TabControl.OnMouseMove := TOnMouse(MakeMethod(nil, @MouseMove));
for i := 0 to 9 do
TabControl.TC_Insert(i, Int2Str(i), 0).Hint.Text := Int2Str(i);
Run(Applet);
end.
-
program TabTest;
uses
Windows, Messages, KOL;
var
TabControl: PControl;
i: Integer;
PrevX, PrevY: Word;
PrevIdx: Integer;
procedure MouseMove(Dummy: Pointer; Sender: PControl; var Mouse: TMouseEventData);
var
TabIndex: Integer;
begin
TabIndex := TabControl.TC_TabAtPos(Mouse.X, Mouse.Y);
if (TabIndex >= 0) then
begin
if ((abs(PrevX - Mouse.X) < 8) and (abs(PrevY - Mouse.y) < 8)) and (PrevIdx = TabIndex) then
Exit;
TabControl.Hint.Text := TabControl.Pages[TabIndex].Hint.Text;
PrevX := Mouse.X;
PrevY := Mouse.Y;
PrevIdx := TabIndex;
end;
end;
begin
Applet := NewForm(nil, '');
TabControl := NewTabControl(Applet, [], [], nil, 0).SetAlign(caClient);
TabControl.OnMouseMove := TOnMouse(MakeMethod(nil, @MouseMove));
for i := 0 to 9 do
TabControl.TC_Insert(i, Int2Str(i), 0).Hint.Text := Int2Str(i);
Run(Applet);
end.
-
Thank you very much for the reply, it works well.
Any suggestions for my other question?:
> Jon © (26.09.10 18:16) [2] > > Also, how can I obtain which tab a control is placed on? > ... > Sender.Parent.Caption := Sender.Caption; // Sender.Parent is incorrect?
-
function GetParentTabIdx(Control: PControl): Integer;
var i: Integer;
begin
Result := -1;
for i := 0 to TabControl.Count - 1 do
if Control.Parent.Handle = TabControl.TC_pages[i].Handle then
begin
Result := i;
break;
end;
end;
-
Thank you. Your logic is good, you make it look very easy.
-
One last question concerning TabControl: is it possible to remove the border from each page?
-
TabControl.Border := 0; ?
-
No, I wish that it was that easy! I have tried various methods:
program TabTest;
uses
Windows, Messages, KOL;
var
TabControl, TabSheet: PControl;
Rect: TRect;
begin
Applet := NewForm(nil, 'TabTest');
Applet.Border := 0;
Applet.Color := clRed;
TabControl := NewTabcontrol(Applet, [], [], nil, 0).SetAlign(caClient);
TabControl.Border := 0;
TabSheet := TabControl.TC_Insert(0, 'TabBorderTest', -2);
TabSheet.Border := 0;
TabControl.Style := TabControl.Style and (not WS_DLGFRAME) and (not SS_SUNKEN);
TabSheet.Style := TabSheet.Style and (not WS_DLGFRAME) and (not SS_SUNKEN);
Rect := TabSheet.ClientRect;
InflateRect(Rect, 4, 4);
Run(Applet);
end.
Any other ideas?
-
TabControl.Border := -4; ?
-
Yes, good thinking again. It's crude, but it does work. Thank you.
|