加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

delphi – 是否可以更改TTabSheet选项卡的颜色

发布时间:2020-12-15 09:17:02 所属栏目:大数据 来源:网络整理
导读:我正在跑Lazarus 0.9.30.2. 我有一个TForm,其中有一个TPageControl.在TPageControl中有一系列TTabSheets(大约30个).我想要做的是对标签进行颜色编码,因此前10个为红色,后10个为蓝色,后10个为绿色.我已经看到内联网上的代码片段,当您单击它们并导航到它们(以
我正在跑Lazarus 0.9.30.2.
我有一个TForm,其中有一个TPageControl.在TPageControl中有一系列TTabSheets(大约30个).我想要做的是对标签进行颜色编码,因此前10个为红色,后10个为蓝色,后10个为绿色.我已经看到内联网上的代码片段,当您单击它们并导航到它们(以突出显示活动选项卡)时,它会更改选项卡表颜色(包括选项卡本身),但我想要做的是如上所述对它们进行着色.标签页首先加载.

有办法做到这一点吗?

解决方法

如果只有在禁用主题的 Windows上才能获得有点棘手的解决方案,那么请尝试以下方法:

从项目/项目选项…项目设置对话框中取消选中使用清单文件以启用主题(仅限Windows)选项,并将以下代码粘贴到具有页面控制的单元中.它使用插入的类,因此它只能在粘贴此代码的单元中使用.

uses
  ComCtrls,Windows,LCLType;

type
  TPageControl = class(ComCtrls.TPageControl)
  private
    procedure CNDrawItem(var Message: TWMDrawItem); message WM_DRAWITEM;
  protected
    procedure CreateParams(var Params: TCreateParams); override;
  end; 

implementation

procedure TPageControl.CreateParams(var Params: TCreateParams);
begin
  inherited CreateParams(Params);
  with Params do
  begin
    if not (csDesigning in ComponentState) then
      Style := Style or TCS_OWNERDRAWFIXED;
  end;
end;

procedure TPageControl.CNDrawItem(var Message: TWMDrawItem);
var
  BrushHandle: HBRUSH;
  BrushColor: COLORREF;
begin
  with Message.DrawItemStruct^ do
  begin
    case itemID of
      0: BrushColor := RGB(235,24,33);
      1: BrushColor := RGB(247,200,34);
      2: BrushColor := RGB(178,229,26);
    else
      BrushColor := ColorToRGB(clBtnFace);
    end;
    BrushHandle := CreateSolidBrush(BrushColor);
    FillRect(hDC,rcItem,BrushHandle);
    SetBkMode(hDC,TRANSPARENT);
    DrawTextEx(hDC,PChar(Page[itemID].Caption),-1,DT_CENTER or 
      DT_VCENTER or DT_SINGLELINE,nil);
  end;
  Message.Result := 1;
end;

这是它的样子(丑陋:)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读