Einzelnen Beitrag anzeigen

Benutzerbild von Bummi
Bummi

Registriert seit: 15. Jun 2010
Ort: Augsburg Bayern Süddeutschland
3.470 Beiträge
 
Delphi XE3 Enterprise
 
#8

AW: Kann mir das einer mit ListBoxDrawItem und odFocused erklären

  Alt 15. Okt 2012, 20:21
Delphi-Quellcode:
unit Unit3;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type

  TListbox=Class(StdCtrls.TListBox)
    procedure CNDrawItem(var Message: TWMDrawItem); message CN_DRAWITEM;
  End;


  TForm3 = class(TForm)
    ListBox1: TListBox;
    procedure FormCreate(Sender: TObject);
    procedure ListBox1DrawItem(Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState);
  private
    Fcanvas:TCanvas;
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form3: TForm3;

implementation

{$R *.dfm}

procedure TForm3.FormCreate(Sender: TObject);
var
 i:Integer;
begin
    Fcanvas := TCanvas.Create;
    for I := 1 to 10 do
      Listbox1.Items.Add('testdfdsf');
end;

procedure TForm3.ListBox1DrawItem(Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState);
begin
 with TListBox(Control).Canvas do
      begin
      if odSelected in State then Brush.Color := clLime else Brush.Color := $EEEEEE;
      Fillrect(rect);
      Textout(rect.Left,rect.Top,TListBox(Control).Items[Index]);
      end;

end;

{ TListbox }


procedure TListbox.CNDrawItem(var Message: TWMDrawItem);
var
 w:TOwnerDrawState;
begin
  w := TOwnerDrawState(LoWord(Message.DrawItemStruct^.itemState));
  Exclude(w , odFocused);
  Message.DrawItemStruct^.itemState := Message.DrawItemStruct^.itemState and ( $FFFF0000 + Word(w));
  inherited;
end;

end.
Thomas Wassermann H₂♂
Das Problem steckt meistens zwischen den Ohren
DRY DRY KISS
H₂ (wenn bei meinen Snipplets nichts anderes angegeben ist Lizenz: WTFPL)
  Mit Zitat antworten Zitat