Setting TTabControl color after XPManifest in Delphi

烈酒焚心 提交于 2021-01-24 11:07:55

问题


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?


回答1:


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.

see this example.

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;


来源:https://stackoverflow.com/questions/1812479/setting-ttabcontrol-color-after-xpmanifest-in-delphi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!