| Код | unit Unit1;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;
type TForm1 = class(TForm) ListBox1: TListBox; procedure FormCreate(Sender: TObject); procedure ListBox1DrawItem(Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState); private { Private declarations } public { Public declarations } end;
var Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject); begin with ListBox1, Items do begin Style := lbOwnerDrawFixed; Append('First'); Append('Second'); Append('Third'); end; end;
procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState); var Flags: Longint; S: String; begin with (Control as TListBox), Canvas do begin { Условие определяет, какие итемы выделять } if odSelected in State then Brush.Color := clRed; FillRect(Rect); Flags := DrawTextBiDiModeFlags(DT_SINGLELINE or DT_VCENTER or DT_NOPREFIX); if not UseRightToLeftAlignment then Inc(Rect.Left, 2) else Dec(Rect.Right, 2); S := Items[Index]; DrawText(Canvas.Handle, PChar(S), Length(S), Rect, Flags); end; end;
end.
|
|