TPageControl DrawTab 出现问题

发布于 2024-12-02 02:32:46 字数 767 浏览 0 评论 0原文

我将 TPageControl 样式设置为平面按钮 (tsFlatButtons),并使用 OnDrawTab 事件更改选项卡的按钮颜色。

它可以工作,但是未激活的按钮有灰色(btnFace 颜色)边框! 在此处输入图像描述

知道如何解决此问题吗?

procedure TForm1.PageControlDrawTab(Control: TCustomTabControl;
          TabIndex: Integer; const Rect: TRect; Active: Boolean);

var
  AText: string;
  ARect: TRect;

begin
  with (Control as TPageControl).Canvas do
  begin
    ARect := Rect;
    OffsetRect(ARect, 0, 4);

    Brush.Color := COLOR1;
    FillRect(Rect);

    AText := TPageControl(Control).Pages[TabIndex].Caption;

    with Control.Canvas do   
      DrawText(Control.Canvas.Handle, PChar(AText), -1,ARect, DT_CENTER or DT_SINGLELINE);

  end;
end;

I set the TPageControl Style to Flat Buttons (tsFlatButtons), and change the tab's button color using the OnDrawTab event.

It works, but the button that is not-active has grey (btnFace color) border!
enter image description here

Any idea how to fix this?

procedure TForm1.PageControlDrawTab(Control: TCustomTabControl;
          TabIndex: Integer; const Rect: TRect; Active: Boolean);

var
  AText: string;
  ARect: TRect;

begin
  with (Control as TPageControl).Canvas do
  begin
    ARect := Rect;
    OffsetRect(ARect, 0, 4);

    Brush.Color := COLOR1;
    FillRect(Rect);

    AText := TPageControl(Control).Pages[TabIndex].Caption;

    with Control.Canvas do   
      DrawText(Control.Canvas.Handle, PChar(AText), -1,ARect, DT_CENTER or DT_SINGLELINE);

  end;
end;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

写给空气的情书 2024-12-09 02:32:46

作为解决方法,如果设计适合您
在此处输入图像描述
,您可以隐藏当前选项卡:

  for I := 0 to Pred(PageControl1.PageCount) do
    PageControl1.Pages[I].TabVisible := False;

并添加一个 TTabSet
具有这些属性:

BackgroundColor := clGradientActiveCaption;
SelectedColor := clGradientActiveCaption;
Style := tsModernTabs

As a workaround, if the design is ok for you
enter image description here
, you can hide the current tabs:

  for I := 0 to Pred(PageControl1.PageCount) do
    PageControl1.Pages[I].TabVisible := False;

and add a TTabSet
with these properties:

BackgroundColor := clGradientActiveCaption;
SelectedColor := clGradientActiveCaption;
Style := tsModernTabs
空城缀染半城烟沙 2024-12-09 02:32:46

我知道这是一篇非常旧的帖子,但由于它没有完整的答案,而且我遇到了同样的问题,最终找到了如何做到这一点,我想我应该让你知道......

此外,如果某些选项卡的 tabvisible 设置为 False
我认为解决此问题的最佳方法是使用整数 i 循环选项卡:

for I := 0 to TPageControl(Control).PageCount-1 do
  if TPageControl(Control).Pages[I].TabIndex = TabIndex then
begin
  FillRect(Control.Canvas.Handle,aRect,Control.Canvas.Brush.Handle);
  // Do your text drawing here
  break;
end;

I know this is a very old post but since it does not have a complete answer and I had the same problem and finally found out how to do it, I thought I should let you know...

Also your code does not work well if some of the tabs have tabvisible set to False
Here is I think the best way to fix this, using an integer i to loop the tabs:

for I := 0 to TPageControl(Control).PageCount-1 do
  if TPageControl(Control).Pages[I].TabIndex = TabIndex then
begin
  FillRect(Control.Canvas.Handle,aRect,Control.Canvas.Brush.Handle);
  // Do your text drawing here
  break;
end;
岁吢 2024-12-09 02:32:46

请参阅下面的本单元,修复 Win64 位上的绘图问题

https://forums.embarcadero.com/ thread.jspa?messageID=292598

See this unit below, to fix Draw problems on Win64bits

https://forums.embarcadero.com/thread.jspa?messageID=292598

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文