在 Delphi 中的 XPManifest 之后设置 TTabControl 颜色 [英] Setting TTabControl color after XPManifest in Delphi

查看:27
本文介绍了在 Delphi 中的 XPManifest 之后设置 TTabControl 颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的表单上有 tabcontrol 组件.放 XPManifest 后,它的颜色变成了白色,我想改变它,但找不到颜色属性.而且我也不想删除 XPManifest.有没有办法解决这个问题?

I have tabcontrol component on my form. After I put XPManifest, its color became white, I want to change it, but couldn't find color property. And I don't want to remove XPManifest as well. Is there any way to solve this issue?

推荐答案

要改变 TTabControl 的颜色,必须将 OwnerDraw 属性设置为 true false 并编写自己的在 OnDrawTab 事件中绘制选项卡和背景的代码.

To change the color of a TTabControl must put the OwnerDraw property to true false and write your own code to draw the tabs and the background in the OnDrawTab Event.

看这个例子.

procedure TForm38.TabControl1DrawTab(Control: TCustomTabControl; TabIndex: Integer; const Rect: TRect; Active: Boolean);
var
y    : Integer;
x    : Integer;
aRect: TRect;
begin
  if Active then
  begin
    //Fill the tab rect
    Control.Canvas.Brush.Color := clWebGainsboro;
    Control.Canvas.FillRect(Rect);        
    //Fill the background
    aRect.Left:=1;
    aRect.Right:=Control.Width-1;
    aRect.Bottom:=Control.Height-1;
    aRect.Top:=Rect.Bottom+1;
    Control.Canvas.FillRect(aRect);   
  end
  else
  begin
    //Fill the tab rect
    Control.Canvas.Brush.Color := clBtnFace;
    Control.Canvas.FillRect(Rect);
  end;

  y  := Rect.Top + ((Rect.Bottom - Rect.Top - Control.Canvas.TextHeight(TTabControl(Control).Tabs[TabIndex])) div 2) + 1;
  x  := Rect.Left + ((Rect.Right - Rect.Left - Control.Canvas.TextWidth (TTabControl(Control).Tabs[TabIndex])) div 2) + 1;
  //draw the tab title
  Control.Canvas.TextOut(x,y,TTabControl(Control).Tabs[TabIndex]);
end;

这篇关于在 Delphi 中的 XPManifest 之后设置 TTabControl 颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆