Einzelnen Beitrag anzeigen

marabu

Registriert seit: 6. Apr 2005
10.109 Beiträge
 
#2

Re: Listbox markieren

  Alt 27. Feb 2006, 20:37
Herzlich willkommen in der Delphi-PRAXiS, Christian.

Wenn du der ListBox den Style lbOwnerDrawFixed gibst, dann funktioniert das hier:

Delphi-Quellcode:
type
  TDemoForm = class(TForm)
    ListBox: TListBox;
    Memo: TMemo;
    InitButton: TButton;
    procedure ListBoxDrawItem(Control: TWinControl; Index: Integer;
      Rect: TRect; State: TOwnerDrawState);
    procedure InitButtonClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    fs: TFormatSettings;
  end;

// ...

procedure TDemoForm.ListBoxDrawItem(Control: TWinControl; Index: Integer;
  Rect: TRect; State: TOwnerDrawState);
var
  s: String;
  dt: TDateTime;
begin
  with Control as TListbox do
  begin
    Canvas.FillRect(Rect);
    s := Copy(Items[Index], Length(Items[Index]) - 7, 8);
    if TryStrToDate(s, dt, fs) and (dt < Trunc(Date)) then
    begin
      Canvas.Brush.Color := clRed;
      Canvas.Font.Color := clWhite;
    end else begin
      Canvas.Brush.Color := clWhite;
      Canvas.Font.Color := clBlack;
    end;
    Canvas.TextOut(Rect.Left, Rect.Top, Items[Index]);
  end;
end;

procedure TDemoForm.FormCreate(Sender: TObject);
begin
  GetLocaleFormatSettings(GetUserDefaultLCID, fs);
  fs.DateSeparator := '.';
  fs.ShortDateFormat := 'dd.mm.yy';
end;
Grüße vom marabu
  Mit Zitat antworten Zitat