AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Falsche Fontfarbe

Ein Thema von EWeiss · begonnen am 8. Okt 2016 · letzter Beitrag vom 8. Okt 2016
Antwort Antwort
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
EWeiss
(Gast)

n/a Beiträge
 
#2

AW: Falsche Fontfarbe

  Alt 8. Okt 2016, 19:47
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:
  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
  Mit Zitat antworten Zitat
Benutzerbild von Luckie
Luckie

Registriert seit: 29. Mai 2002
37.621 Beiträge
 
Delphi 2006 Professional
 
#3

AW: Falsche Fontfarbe

  Alt 8. Okt 2016, 20:04
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.
Michael
Ein Teil meines Codes würde euch verunsichern.
  Mit Zitat antworten Zitat
EWeiss
(Gast)

n/a Beiträge
 
#4

AW: Falsche Fontfarbe

  Alt 8. Okt 2016, 20:09
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.
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

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

Registriert seit: 29. Mai 2002
37.621 Beiträge
 
Delphi 2006 Professional
 
#5

AW: Falsche Fontfarbe

  Alt 8. Okt 2016, 20:15
http://www.delphipraxis.net/16539-colorref-tcolor.html
http://stackoverflow.com/questions/5...or-to-colorref
Michael
Ein Teil meines Codes würde euch verunsichern.
  Mit Zitat antworten Zitat
EWeiss
(Gast)

n/a Beiträge
 
#6

AW: Falsche Fontfarbe

  Alt 8. Okt 2016, 20:18
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
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 05:29 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