Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Programmieren allgemein (https://www.delphipraxis.net/40-programmieren-allgemein/)
-   -   Delphi Falsche Fontfarbe (https://www.delphipraxis.net/190488-falsche-fontfarbe.html)

EWeiss 8. Okt 2016 18:04


Falsche Fontfarbe
 
Meine Checkbox hat die Fontfarbe "clWindowText" sollte in dem fall 0 sein.


Eigentlich sollte es ausreichen den Font zu übergeben und anschließend die Farbe daraus zu ermitteln.
Tut es aber anscheinend nicht.
Deshalb habe ich Jetzt die Farbe mal gesondert übergeben.


Delphi-Quellcode:
CK.Font := Form1.CheckBox1.Font;
CK.FontColor := Form1.CheckBox1.Font.Color;
CK.BackColor := Form1.CheckBox1.Color;
Wenn ich jetzt meinen LogFont erstelle.. und den Text zeichne ist die Farbe falsch.

Delphi-Quellcode:
procedure THookedCheckBox.DrawCaption(WinHandle: HWND; DC: HDC; Size: TRect; Disabled: BOOL);
var
  Brush: HBrush;
  Color: Colorref;
  crFont: HFONT;
  FontOld: HFont;
  Caption: WideString;
  rc: TRect;
  LogFont: TLOGFONT;

begin

  FillChar(LogFont, SizeOf(TLOGFONT), 0);

  Color := BackColor;
  Brush := CreateSolidBrush(TranslateColor(Color));
  FillRect(DC, Size, Brush);
  DeleteObject(Brush);

  StrPCopy(LogFont.lfFaceName, Font.Name);
  LogFont.lfHeight := (Font.Size * -20) div 15;
  LogFont.lfWeight := 500;
  LogFont.lfItalic := IIf(Font.Style = [fsItalic], 1, 0);
  LogFont.lfUnderline := IIf(Font.Style = [fsUnderline], 1, 0);
  LogFont.lfStrikeOut := IIf(Font.Style = [fsStrikeOut], 1, 0);
  LogFont.lfQuality := ANTIALIASED_QUALITY;

  Caption := GetWindowText(CtrlHwnd);
  crFont := CreateFontIndirect(LogFont);
  FontOld := SelectObject(DC, crFont);
  SetBkMode(DC, TRANSPARENT);
  SetTextColor(DC, FontColor);
  CopyRect(rc, Size);
  rc.left := CheckWidth + 4;
  DrawText(DC, Caption, -1, rc, DT_LEFT or DT_VCENTER or DT_SINGLELINE);

  if Disabled then
  begin
    OffsetRect(rc, -1, -1);
    SetTextColor(DC, $CCCCCC);
    DrawText(DC, Caption, -1, rc, DT_LEFT or DT_VCENTER or DT_SINGLELINE);
  end;

  SelectObject(DC, FontOld);
  DeleteObject(crFont);

end;
Die Farbe die übergeben wird (Aus der Form1)
Form1.CheckBox1.Color; = -16777201
Form1.CheckBox1.Font.Color; = -16777208

Warum ? Wenn Form1.CheckBox1.Font.Color eigentlich clWindowText ist.
Sollte eigentlich 0 sein in dem Fall.

Sieht dann aus wie auf dem Bild! Im Anhang siehe Checkboxen.
Wenn da Fehler in der Zuweisung der Fontstyle vorliegen bitte bescheid geben das scheint auch nicht so zu funktionieren wie es soll.
Die 3 Checkbox hat fsUnderline wird aber nicht erkannt.


Funktioniert musste nur alle Checkboxen übergeben nicht nur den Font von einer.
Delphi-Quellcode:
       if TWinControl(Comp.Controls[i]) = Form1.CheckBox1 then
       begin
         CB.Font := Form1.CheckBox1.Font;
         CB.FontColor := Form1.CheckBox1.Font.Color;
         CB.BackColor := Form1.CheckBox1.Color;
         CB.Connect;
       end else if TWinControl(Comp.Controls[i]) = Form1.CheckBox2 then
       begin
         CB.Font := Form1.CheckBox2.Font;
         CB.FontColor := Form1.CheckBox2.Font.Color;
         CB.BackColor := Form1.CheckBox2.Color;
         CB.Connect;
       end else if TWinControl(Comp.Controls[i]) = Form1.CheckBox3 then
       begin
         CB.Font := Form1.CheckBox3.Font;
         CB.FontColor := Form1.CheckBox3.Font.Color;
         CB.BackColor := Form1.CheckBox3.Color;
         CB.Connect;
       end;
Aber die bescheidenen Farben wollen einfach nicht.

gruss

EWeiss 8. Okt 2016 19:47

AW: Falsche Fontfarbe
 
Ok :)
Anscheinend will oder kann mir niemand helfen.

Habe es jetzt selbst bereinigt.
Das Problem ist das TColor nicht gleich System Color ist.
Deshalb musste ich die Farben übersetzen. (Was für eine Schmarrn)

Anwendung:
Delphi-Quellcode:
       if TWinControl(Comp.Controls[i]) = Form1.CheckBox1 then
       begin
         CB.Font := Form1.CheckBox1.Font;
         CB.BackColor := Form1.CheckBox1.Color;
         CB.Connect;
       end else if TWinControl(Comp.Controls[i]) = Form1.CheckBox2 then
       begin
         CB.Font := Form1.CheckBox2.Font;
         CB.BackColor := Form1.CheckBox2.Color;
         CB.Connect;
       end else if TWinControl(Comp.Controls[i]) = Form1.CheckBox3 then
       begin
         CB.Font := Form1.CheckBox3.Font;
         CB.BackColor := Form1.CheckBox3.Color;
         CB.Connect;
       end;
DLL:
Delphi-Quellcode:
  SetTextColor(DC, TranslateColor(Font.Color));
Delphi-Quellcode:
function TranslateColor(AClr: Integer): Colorref;
begin

  If (AClr and $80000000) = $80000000 then
    Result := GetSysColor(AClr and $FF)
  else
    Result := AClr;
end;
gruss

Luckie 8. Okt 2016 20:04

AW: Falsche Fontfarbe
 
Delphi-Quellcode:
Form1.CheckBox1.Color; = -16777201
Sieht irgendwie nach einem Integerüberlauf aus oder so. Als wenn die Datentypen nicht zusammen passen. Hast du dir mal die Konstanten angeguckt?

PS: Du arbeitest gerade ziemlich am Limit. Da gibt es wenig Experten, die so tief in der Materie drin stecken. :wink:

EWeiss 8. Okt 2016 20:09

AW: Falsche Fontfarbe
 
Zitat:

Zitat von Luckie (Beitrag 1350234)
Delphi-Quellcode:
Form1.CheckBox1.Color; = -16777201
Sieht irgendwie nach einem Integerüberlauf aus oder so. Als wenn die Datentypen nicht zusammen passen. Hast du dir mal die Konstanten angeguckt?

PS: Du arbeitest gerade ziemlich am Limit. Da gibt es wenig Experten, die so tief in der Materie drin stecken. :wink:

Das ist die Farbe die mir von TColor also Form1.CheckBox1.Font zurück gegeben wird.
Deshalb muss ich sie nach System Color Konvertieren.

Warum das so ist kann ich nicht sagen jedenfalls funktioniert es nur so.
Danach funktioniert es gut.. siehe shot.

TColor <> Colorref

gruss

Luckie 8. Okt 2016 20:15

AW: Falsche Fontfarbe
 
http://www.delphipraxis.net/16539-colorref-tcolor.html
http://stackoverflow.com/questions/5...or-to-colorref

EWeiss 8. Okt 2016 20:18

AW: Falsche Fontfarbe
 
Ja deshalb muss ich die Farbe auch konvertieren.. TFont gibt mir nun mal nur TColor anstelle von Colorref zurück.
Na ja jetzt funktioniert es ja.

gruss


Alle Zeitangaben in WEZ +1. Es ist jetzt 14:28 Uhr.

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