开发者

Trouble with TPageControl DrawTab

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!

Trouble with TPageControl DrawTab

Any idea how to fix this?

开发者_StackOverflow社区
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;


As a workaround, if the design is ok for you

Trouble with TPageControl DrawTab

, 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


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;


See this unit below, to fix Draw problems on Win64bits

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜