2008. október 7., kedd

Change the color of the tabs on a PageControl


Problem/Question/Abstract:

How do I change the color of the tabs on a PageControl?

Answer:

The example below uses the OnDrawCell event to change the colour of the active Tab and of the Font used:

procedure TForm1.TabControl1DrawTab(Control: TCustomTabControl;
  TabIndex: Integer; const Rect: TRect; Active: Boolean);
var
  s: string;
  r: TRect;
begin
  s := form1.TabControl1.Tabs.Strings[tabindex];
  r := Rect;
  with Control.Canvas do
  begin
    if Active then
    begin
      Brush.Color := clinfoBK;
      Font.Color := clBlue;
    end;
    Windows.FillRect(Handle, r, Brush.Handle);
    OffsetRect(r, 0, 1);
    DrawText(Handle, PChar(s), Length(s), r, DT_CENTER or DT_SINGLELINE or
      DT_VCENTER);
  end;
end;

Nincsenek megjegyzések:

Megjegyzés küldése