選択したタブの色を変更するにはどうしたら良いのですか?
TabControl1.Canvas.Brush.Color:= clWhite;
で全ての色は変更できるのですが、一つだけ選択して
変更することができません。
付け加えて、タブの右下にタブができてもいいように線がありますが、
取れるのであればとりたいです。
よろしくお願いします。
> 選択したタブの色を変更するにはどうしたら良いのですか?
OnDrawTabイベントはどうでしょうか?
OnDrawTabイベント上に
TabControl1.Canvas.Brush.Color:= clWhite;
上記の記述では、タブ全体が白色になってしまい
選択したタブをグレーにし、
選択されていないタブは白としたいのですが、
選択したタブに色を指定することができません。
申し訳ありませんが、もう少し詳しく教えていただけますか。
TabControl1のOwnerDrawプロパティをTrueにしておいて
OnDrawTabイベントを
procedure TForm1.TabControl1DrawTab(Control: TCustomTabControl;
TabIndex: Integer; const Rect: TRect; Active: Boolean);
begin
if Active then
Control.Canvas.Brush.Color := clGray
else
Control.Canvas.Brush.Color := clWhite;
Control.Canvas.FillRect(Rect);
end;
じゃないかなと思います。
OnDrawTabイベントはタブごとに取得できるんですね。
(間違えて覚えていました・・・。)
色を変えることはできたのですが、
文字が消えてしまいました。
どうしたら、文字が表示されるのでしょうか?
Control.Canvas.Font.Color := clWhite;
では、ダメなのでしょうか。
例えば
procedure TForm1.TabControl1DrawTab(Control: TCustomTabControl;
TabIndex: Integer; const Rect: TRect; Active: Boolean);
begin
if Active then
Control.Canvas.Brush.Color := clGray
else
Control.Canvas.Brush.Color := clWhite;
Control.Canvas.FillRect(Rect);
Control.Canvas.TextOut(Rect.Left+4,Rect.Top+3,
TTabControl(Control).Tabs[TabIndex]);
end;
こんなかんじかなと思います。
procedure TForm1.TabControl1DrawTab(Control: TCustomTabControl;
TabIndex: Integer; const Rect: TRect; Active: Boolean);
var
R: TRect;
begin
R := Rect;
with Control.Canvas do begin
if Active then begin
Brush.Color := clAqua;
Font.Color := clBlue;
Font.Style := [fsBold];
InflateRect(R, -1, -1);
end else begin
Brush.Color := clWhite;
Font.Color := clBlack;
Font.Style := [];
OffsetRect(R, 0, 2);
end;
FillRect(R);
TextOut(Rect.Left+4, Rect.Top+4, TTabControl(Control).Tabs[TabIndex]);
end;
end;
文字を表示することができました。
「通りすがり」さん、「微調整」さん
本当にありがとうございました。
ツイート | ![]() |