Develop a strong foundation and understanding of web design by learning HTML, CSS, and additional tools to help you develop your own website.
Do more with
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, shellapi;
type
TForm1 = class(TForm)
ComboBox1: TComboBox;
procedure FormCreate(Sender: TObject);
procedure ComboBox1DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
const Colors: array[0..2] of TColor =
(clGreen, clRed, clYellow) ;
implementation
{$R *.DFM}
procedure TForm1.FormCreate(Sender: TObject);
begin
ComboBox1.Items.Add('Item 1');
ComboBox1.Items.Add('Item 2');
ComboBox1.Items.Add('Item 3');
ComboBox1.ItemIndex := 0;
end;
procedure TForm1.ComboBox1DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
begin
with Control as TComboBox do
begin
Canvas.Brush.Color := TColor(Colors[Index]);
Canvas.FillRect(Rect);
Canvas.TextOut(Rect.Left,Rect.Top, ComboBox1.Items[Index])
end;
end;
end.
Premium Content
You need an Expert Office subscription to comment.Start Free Trial