Delphi-PRAXiS
Seite 1 von 2  1 2      

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   GUI-Design mit VCL / FireMonkey / Common Controls (https://www.delphipraxis.net/18-gui-design-mit-vcl-firemonkey-common-controls/)
-   -   Delphi Farbige Schrift beim TPageControl Tab... (https://www.delphipraxis.net/160313-farbige-schrift-beim-tpagecontrol-tab.html)

Z4ppy 6. Mai 2011 21:12

Farbige Schrift beim TPageControl Tab...
 
Guten Abend DPler,

ich möchte die Caption eines Tabs von TPageControl rot schreiben. Es ist ausserdem noch zu erwähnen, dass ich das XP Manifest verwende, allerdings müsste das für diesen Thread nicht relevant sein, siehe unten.

Natürlich habe ich rumgesucht und folgendes gefunden:
http://www.delphipraxis.net/152850-s...-des-tabs.html
http://www.delphi-forum.de/topic_TPa...n_53796,0.html

Nun gut, sofort ausprobiert, OwnerDraw auf True und folgende OnDrawTab-Methode:
Delphi-Quellcode:
procedure TForm1.PagesDrawTab(Control: TCustomTabControl; TabIndex: Integer; const Rect: TRect; Active: Boolean);
begin
  Control.Canvas.Font.Color := clRed;
  Control.Canvas.TextOut(Rect.Left, Rect.Top, TPageControl(Control).Pages[TabIndex].Caption);
end;
Funktioniert aber nicht, es erscheint gar kein Text!
Ich habe dann über eine MessageBox-Zeile herausgefunden, dass das OnDrawTab-Ereignis gar nicht erst aufgerufen wird - logisch, dass der Text dann nicht gezeichnet wird.

Also weitergesucht und dann bin ich auf diesen Post gestossen: http://www.delphipraxis.net/19747-re...tml#post498127
Auch ein Repaint löst aber OnDrawTab nicht aus.

Wieso zur Hölle ist das so?

MfG Z4ppy

PS.: Ich habe das Ganze in einem neuen Projekt ohne XP-Manifest getestet, auch dort wird meine Methode nicht aufgerufen.

madtom 6. Mai 2011 21:41

AW: Farbige Schrift beim TPageControl Tab...
 
Hallo,

folgender Code sollte den Zweck erfüllen:
(Quelle: http://www.delphi-treff.de/)

Delphi-Quellcode:
procedure TForm1.PageControl1DrawTab(Control: TCustomTabControl;
  TabIndex: Integer; const Rect: TRect; Active: Boolean);
var
  CaptionX: Integer;
  CaptionY: Integer;
  TabCaption: string;
begin
  with Control.Canvas do begin
    case TabIndex of
      0: begin
           Brush.Color := clBtnFace;
           Font.Color := clWindowText;
         end;
      1: begin
           Brush.Color := clMaroon;
           Font.Color := clWhite;
         end;
    end;
    TabCaption := PageControl1.Pages[TabIndex].Caption;
    CaptionX := Rect.Left + ((Rect.Right - Rect.Left - TextWidth(TabCaption)) div 2);
    CaptionY := Rect.Top + ((Rect.Bottom - Rect.Top - TextHeight('Gg')) div 2);
    FillRect(Rect);
    TextOut(CaptionX, CaptionY, TabCaption);
  end;
end;
Thomas

Z4ppy 6. Mai 2011 21:42

AW: Farbige Schrift beim TPageControl Tab...
 
Wie ich schon schrieb: das Problem ist nicht der Code des OnDrawTab, sondern dass diese Methode gar nicht ausgelöst wird ^^
Lesen soll in einigen Fällen Vorteile bieten ;)

MfG Z4ppy

madtom 6. Mai 2011 21:52

AW: Farbige Schrift beim TPageControl Tab...
 
Hallo Z4ppy,

hast Du den Code mal ausprobiert? Ich habe es getestet und der Text wird in meinem Falle weiß auf Maroon ausgegeben. Warum Dein OnDrawTab Ereignis nicht ausgelöst
wird, kann ich aber auch nur mutmaßen.

Z4ppy 6. Mai 2011 21:54

AW: Farbige Schrift beim TPageControl Tab...
 
Was bringt mir der beste Code im OnDrawTab, wenn das Ereignis nicht kommt? :lol:
Ja, ich hab den Code eben ausprobiert... Er ist genau so erfolgreich wie meiner aus dem ersten Post :P

Zitat:

Zitat von madtom (Beitrag 1099418)
Warum Dein OnDrawTab Ereignis nicht ausgelöst wird, kann ich aber auch nur mutmaßen.

Auch Mutmassungen sind gerne gesehen :)

MfG Z4ppy

madtom 6. Mai 2011 22:00

AW: Farbige Schrift beim TPageControl Tab...
 
Hallo Z4ppy,

Hast Du die Eigenschaft "OwnerDraw" der Komponente auf True gesetzt? Sonst kann natürlich OnDrawTab nicht funtionieren.

Z4ppy 6. Mai 2011 22:01

AW: Farbige Schrift beim TPageControl Tab...
 
Ich weise erneut auf meinen Post #1 hin:
Zitat:

Zitat von Z4ppy (Beitrag 1099409)
Nun gut, sofort ausprobiert, OwnerDraw auf True und folgende OnDrawTab-Methode:

MfG Z4ppy

madtom 6. Mai 2011 22:09

AW: Farbige Schrift beim TPageControl Tab...
 
Hallo Z4ppy,

ich bin dann auch mit meinem Latein am Ende. Bei mir hatte alles auf Anhieb geklappt: Neues Projekt, OwnerDraw auf True, den obigen Code reinkopiert... und FARBIG. Fängst Du irgendwo im Programm Botschaften ab, so daß bei Control nichts ankommt?

Thomas :)

Z4ppy 6. Mai 2011 22:17

AW: Farbige Schrift beim TPageControl Tab...
 
Nein, gar nichts...
Neues Projekt, PageControl drauf, New Page, ein Memo drauf damits nich so leer aussieht, OwnerDraw auf True, OnDrawTab-Methode erstellt und dort ein Memo1.Lines.Add('blah') rein zum Überprüfen.
Keine Caption (logisch), kein Eintrag im Memo...

MfG Z4ppy

madtom 6. Mai 2011 22:22

AW: Farbige Schrift beim TPageControl Tab...
 
Hallo Z4ppy,

schau mal: http://www.delphipraxis.net/118613-t...ta-64-bit.html

ich habe ein 32bit Window 7. Vielleicht liegt es daran.

Gruß Thomas :-D


Alle Zeitangaben in WEZ +1. Es ist jetzt 23:28 Uhr.
Seite 1 von 2  1 2      

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz