![]() |
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:
Wenn ich jetzt meinen LogFont erstelle.. und den Text zeichne ist die Farbe falsch.
CK.Font := Form1.CheckBox1.Font;
CK.FontColor := Form1.CheckBox1.Font.Color; CK.BackColor := Form1.CheckBox1.Color;
Delphi-Quellcode:
Die Farbe die übergeben wird (Aus der Form1)
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; 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:
Aber die bescheidenen Farben wollen einfach nicht.
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; gruss |
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:
DLL:
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;
Delphi-Quellcode:
SetTextColor(DC, TranslateColor(Font.Color));
Delphi-Quellcode:
gruss
function TranslateColor(AClr: Integer): Colorref;
begin If (AClr and $80000000) = $80000000 then Result := GetSysColor(AClr and $FF) else Result := AClr; end; |
AW: Falsche Fontfarbe
Delphi-Quellcode:
Sieht irgendwie nach einem Integerüberlauf aus oder so. Als wenn die Datentypen nicht zusammen passen. Hast du dir mal die Konstanten angeguckt?
Form1.CheckBox1.Color; = -16777201
PS: Du arbeitest gerade ziemlich am Limit. Da gibt es wenig Experten, die so tief in der Materie drin stecken. :wink: |
AW: Falsche Fontfarbe
Zitat:
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 |
AW: Falsche Fontfarbe
|
AW: Falsche Fontfarbe
Zitat:
Na ja jetzt funktioniert es ja. gruss |
Alle Zeitangaben in WEZ +1. Es ist jetzt 02:41 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz