Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Object-Pascal / Delphi-Language (https://www.delphipraxis.net/32-object-pascal-delphi-language/)
-   -   Delphi Schrifttyp der Items in ListBox (https://www.delphipraxis.net/114453-schrifttyp-der-items-listbox.html)

mo_greene 25. Mai 2008 20:01


Schrifttyp der Items in ListBox
 
Hallo,

wie kann ich den Schrifttyp der Items in der ListBox während der Laufzeit des Programms auf Fett stellen?

Vielen Dank :-D

DeddyH 25. Mai 2008 20:01

Re: Schrifttyp der Items in ListBox
 
Selber zeichnen

mo_greene 25. Mai 2008 20:02

Re: Schrifttyp der Items in ListBox
 
Zitat:

Zitat von DeddyH
Selber zeichnen

Was bitte? :mrgreen:

DeddyH 25. Mai 2008 20:06

Re: Schrifttyp der Items in ListBox
 
Meine Delphi 7-Hilfe sagt zu "OnDrawItem":
Zitat:

Es folgt eine typische Behandlungsroutine für das Ereignis OnDrawItem. Hier wird in einem Listenfeld mit dem Stil lbOwnerDrawFixed ein Bitmap links neben jedem String gezeichnet.

Windows:
Delphi-Quellcode:
procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer; Rect:TRect;State: TOwnerDrawState);

var
   Bitmap: TBitmap;     { Temporäre Variable für Bitmap }
   Offset: Integer;     { Offset für Text }
begin
   with (Control as TListBox).Canvas do { Ausgabe in Zeichenfläche der Liste, nicht im Formular }
   begin
   FillRect(Rect);      { Rechteck löschen }
   Offset := 2;         { Standard-Offset }
   Bitmap := TBitmap((Control as TListBox).Items.Objects[Index]); { Bitmap abrufen }
   if Bitmap <> nil then

begin
      BrushCopy(Bounds(Rect.Left + Offset, Rect.Top, Bitmap.Width, Bitmap.Height),
         Bitmap, Bounds(0, 0, Bitmap.Width, Bitmap.Height), clRed); { Bitmap anzeigen}
      Offset := Bitmap.width + 6;   { Vier Pixel zwischen Bitmap und Text einfügen}
   end;
   TextOut(Rect.Left + Offset, Rect.Top, (Control as TListBox).Items[Index]) { Text anzeigen }
   end;
end;
Plattformübergreifend:
Delphi-Quellcode:
procedure TForm1.ListBox1DrawItem(Sender: TObject; Index: Integer; Rect:TRect; State: TOwnerDrawState);

var
  Bitmap: TBitmap;     { Temporäre Variable für Bitmap }
  Offset: Integer;     { Offset für Text }
begin
  with (Sender as TListBox).Canvas do { Ausgabe in Zeichenfläche der Liste, nicht im Formular }
  begin
  FillRect(Rect);      { Rechteck löschen }
  Offset := 2;         { Standard-Offset }
  Bitmap := TBitmap((Sender as TListBox).Items.Objects[Index]); { Bitmap abrufen }
  if Bitmap <> nil then

  begin
    Draw(Rect.Left + Offset, Rect.Top, Bitmap); { Bitmap anzeigen}
    Offset := Bitmap.width + 6;   { Vier Pixel zwischen Bitmap und Text einfügen}
  end;
  TextOut(Rect.Left + Offset, Rect.Top, (Sender as TListBox).Items[Index]) { Text anzeigen }
  end;
end;


mkinzler 25. Mai 2008 20:06

Re: Schrifttyp der Items in ListBox
 
Zu englisch OwnerDraw
Event: onDrawItem

Fussball-Robby 25. Mai 2008 20:11

Re: Schrifttyp der Items in ListBox
 
Wieso nicht einfach so:
Delphi-Quellcode:
procedure TForm1.Button1Click(Sender: TObject);
begin
  ListBox1.Font.Style := ListBox1.Font.Style + [fsBold];
end;
:gruebel: :gruebel:
Es sei denn, er will nur einzelne Items fett machen.

mo_greene 25. Mai 2008 20:17

Re: Schrifttyp der Items in ListBox
 
Zitat:

Zitat von Fussball-Robby
Es sei denn, er will nur einzelne Items fett machen.

Ja, ich möchte nur einzelne Items fett machen. :)

Fussball-Robby 25. Mai 2008 20:26

Re: Schrifttyp der Items in ListBox
 
Na gut, dann kannst du dir z.B mal das angucken


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