Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Object-Pascal / Delphi-Language (https://www.delphipraxis.net/32-object-pascal-delphi-language/)
-   -   Delphi TComboBox Schriftart ändern (https://www.delphipraxis.net/195570-tcombobox-schriftart-aendern.html)

Die MiauKatze 10. Mär 2018 11:05

Delphi-Version: 6

TComboBox Schriftart ändern
 
Hey,

ihr kennt doch alle Word oder?

Da kann man ja auch in einer Combobox die schriftart auswählen!
Das hab ich jetzt vor mit Delphi zu machen(die Combobox)! Ich kann mir auch mit
Code:
TComboBox1.Items.Assign(Screen.Fonts);
alle möglichen Schriftarten anzeigen lassen.

Mein Wunsch ist jetzt aber noch, dass die Schriften auch in sich selber gestalten sind, also "Arial" in der Schriftart Arial ist, usw (halt wie in Word).
Hat jemand von euch eine Idee, wie man das machen könnte?


Danke schonmal im voraus!

Delphi.Narium 10. Mär 2018 11:58

AW: TComboBox Schriftart ändern
 
Nur so als Idee:

Wenn man in der Combobox eine Schrift auswählt, dann müsste man doch diese Schrift im Ereignis OnChange bei ComboBox.Font.Name zuweisen können.

Ungefähr sowas:
Delphi-Quellcode:
procedure TForm1.FormCreate(Sender: TObject);
begin
  ComboBox1.Items.Assign(Screen.Fonts);
end;

procedure TForm1.ComboBox1Change(Sender: TObject);
begin
  ComboBox1.Font.Name := ComboBox1.Text;
  // Oder
  ComboBox1.Font.Name := ComboBox1.Items[ComboBox1.ItemIndex];
end;

Bernhard Geyer 10. Mär 2018 12:01

AW: TComboBox Schriftart ändern
 
Da musst du die einzelnen Einträge per OwnerDraw selbst zeichen.

Die MiauKatze 10. Mär 2018 12:36

AW: TComboBox Schriftart ändern
 
Delphi.Narium ich glaube nicht, dass es funktioniert, da man, meines Wissens nach, mit
Code:
ComboBox1.Font.Name
die Schriftart der gesamten ComboBox ändert. Ich werde es aber trotzdem mal versuchen (:



Zitat:

Zitat von Bernhard Geyer (Beitrag 1395724)
Da musst du die einzelnen Einträge per OwnerDraw selbst zeichen.

Danke, das werde ich mal probieren. :D

Delphi.Narium 10. Mär 2018 12:44

AW: TComboBox Schriftart ändern
 
Bin mal ein bisserl auf die Suche gegangen, dabei rausgekommen ist dann dashier:
Delphi-Quellcode:
procedure TForm1.ComboBox1DrawItem(Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState);
begin
  if odSelected in State then begin
    ComboBox1.Canvas.Brush.Style := bsSolid;
    ComboBox1.Canvas.Brush.Color := $00EEEEEE;
    ComboBox1.Canvas.FillRect(Rect);
    ComboBox1.Canvas.Brush.Color := $00DDDDDD;
    ComboBox1.Canvas.Rectangle(10,Rect.Top + 8,20,Rect.Top + 18);
    ComboBox1.Canvas.Font.Color := $00BEBEBE;
    ComboBox1.Canvas.Font.Style := [fsBold];
    ComboBox1.Canvas.Brush.Style := bsClear;
  end else begin
    ComboBox1.Canvas.Brush.Style := bsSolid;
    if Index mod 2 = 0 then ComboBox1.Canvas.Brush.Color := $00D7D7D7
    else ComboBox1.Canvas.Brush.Color := $00DBDBDB;
    ComboBox1.Canvas.FillRect(Rect);
    ComboBox1.Canvas.Font.Color := clBlack;
    ComboBox1.Canvas.Font.Style := [];
    ComboBox1.Canvas.Brush.Style := bsClear;
   end;

   Rect.Top  := Rect.Top + 2;
   Rect.Left := 5;
   Rect.Right := 150;

   ComboBox1.Canvas.Font.Name := 'Tahoma';
   DrawText(ComboBox1.Canvas.Handle,
            PChar(Screen.Fonts.Strings[Index]),-1,
            Rect,DT_RIGHT or DT_SINGLELINE or DT_VCENTER);

   ComboBox1.Canvas.MoveTo(155,Rect.Top - 2);
   ComboBox1.Canvas.LineTo(155,Rect.Top + ComboBox1.ItemHeight + 2);

   ComboBox1.Canvas.Font.Name := ComboBox1.Items[Index];
   ComboBox1.Canvas.Font.Size := 12;
   Rect.Left := Rect.Left + 160;
   Rect.Right := 500;
   DrawText(ComboBox1.Canvas.Handle,
            PChar(Screen.Fonts.Strings[Index]),-1,
            Rect,DT_SINGLELINE or DT_VCENTER);
end;
(Und meine erste Idee war (mal wieder) etwas vorschnell und unüberlegt :-()

Die MiauKatze 10. Mär 2018 13:03

AW: TComboBox Schriftart ändern
 
Zitat:

Zitat von Delphi.Narium (Beitrag 1395729)
Bin mal ein bisserl auf die Suche gegangen, dabei rausgekommen ist dann dashier:

Daaanke :D
Das klappt wunderbar bei mir (:


Alle Zeitangaben in WEZ +1. Es ist jetzt 06:03 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