Einzelnen Beitrag anzeigen

ConstantGardener

Registriert seit: 24. Jan 2006
Ort: Halberstadt
375 Beiträge
 
Delphi 10.4 Sydney
 
#1

Listbox Ownerdraw und Größenänderung

  Alt 11. Okt 2023, 06:49
Hallo zusammen,

ich habe hier ein kleines Problem mit einer Listbox im Ownerdraw Modus unter Delphi 11.3. VCL 32 oder 64 Bit.
Wenn ich die Listbox in der Größe verändere wird nur der aktuelle Eintrag neu gezeichnet. Das führt dann zu Darstellungsfehlern sobal die Listbox größer wird.
Ist leicht zu reproduzieren: Listbox1 aufs Formular. Align auf alClient, Modus auf ownerdrawfixed, Items mit 4-5 Strings vollschreiben und das im DrawItem.

Delphi-Quellcode:
unit Unit13;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;

type
  TForm13 = class(TForm)
    ListBox1: TListBox;
    procedure ListBox1DrawItem(Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form13: TForm13;

implementation

{$R *.dfm}

procedure TForm13.ListBox1DrawItem(Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState);
var ACanvas : TCanvas;
begin
 ACanvas:=(Control as TListbox).Canvas;
 ACanvas.Brush.Color:=clTeal;
 ACanvas.Brush.style:=bsSolid;
 ACanvas.FillRect(Rect);

 ACanvas.TextOut (Rect.left+10,Rect.Top+2,ListBox1.Items[Index]);
 ACanvas.TextOut (Rect.right-ACanvas.TextWidth(ListBox1.Items[Index]),Rect.Top+2,ListBox1.Items[Index]);
end;

end.
Kann das jemand nachvollziehen? bzw. mir sagen was ich falsch mache (btw. zeichne seit Jahren Listboxen usw. selbst! Stehe aber scheinbar auf dem Schlauch)?
Andreas Schachtner
  Mit Zitat antworten Zitat