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

delphi组框标题颜色变化

发布时间:2020-12-15 09:22:43 所属栏目:大数据 来源:网络整理
导读:我正在使用BDS 2006,并想知道你是否可以使用项目中存在的XPmanifest更改Group-box和radio组标题的颜色(因为它总是蓝色). 解决方法 唯一的方法是覆盖 TGroupBox 的Paint方法. 检查此示例使用Interposer类 type TGroupBox = class(StdCtrls.TGroupBox) //decla
我正在使用BDS 2006,并想知道你是否可以使用项目中存在的XPmanifest更改Group-box和radio组标题的颜色(因为它总是蓝色).

解决方法

唯一的方法是覆盖 TGroupBox的Paint方法.

检查此示例使用Interposer类

type
  TGroupBox = class(StdCtrls.TGroupBox) //declare this before of your form definition
  public
    procedure Paint; override;
  end;

uses
 Themes;

{ TGroupBox }

procedure TGroupBox.Paint;
var
  H: Integer;
  R: TRect;
  Flags: Longint;
  CaptionRect,OuterRect: TRect;
  Size: TSize;
  Box: TThemedButton;
  Details: TThemedElementDetails;
begin
  with Canvas do
  begin
    Font := Self.Font;

    if ThemeControl(Self) then
    begin
      if Text <> '' then
      begin
        GetTextExtentPoint32(Handle,PChar(Text),Length(Text),Size);
        CaptionRect := Rect(0,Size.cx,Size.cy);
        if not UseRightToLeftAlignment then
          OffsetRect(CaptionRect,8,0)
        else
          OffsetRect(CaptionRect,Width - 8 - CaptionRect.Right,0);
      end
      else
        CaptionRect := Rect(0,0);

      OuterRect := ClientRect;
      OuterRect.Top := (CaptionRect.Bottom - CaptionRect.Top) div 2;
      with CaptionRect do
        ExcludeClipRect(Handle,Left,Top,Right,Bottom);
      if Enabled then
        Box := tbGroupBoxNormal
      else
        Box := tbGroupBoxDisabled;
      Details := ThemeServices.GetElementDetails(Box);
      //Draw the themed frame
      ThemeServices.DrawElement(Handle,Details,OuterRect);    
      SelectClipRgn(Handle,0);
      if Text <> '' then
      begin
         H := TextHeight('0');
         if not UseRightToLeftAlignment then
           R := Rect(8,H)
         else
           R := Rect(R.Right - Canvas.TextWidth(Text) - 8,H);
         Flags := DrawTextBiDiModeFlags(DT_SINGLELINE);
         //Now using the Windows.DrawText 
         DrawText(Handle,R,Flags or DT_CALCRECT);
         Brush.Color := Color;//background color of the caption
         Font.Color := clRed;//the color of the caption.
         DrawText(Handle,Flags);
      end;
    end
    else
    inherited;   //if the control is not themed then use the original paint method.
  end;
end;

(编辑:李大同)

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

    推荐文章
      热点阅读