Thema: Delphi Falsche Fontfarbe

Einzelnen Beitrag anzeigen

EWeiss
(Gast)

n/a Beiträge
 
#1

Falsche Fontfarbe

  Alt 8. Okt 2016, 18:04
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

Geändert von EWeiss (11. Jul 2019 um 15:45 Uhr)
  Mit Zitat antworten Zitat