Style:=csOwnerDrawVariable; OnMeMeasureItem事件中设置高度 procedure TForm1.CBBoxDrawItem(Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState); var lrc,rrc:TRect; bc:TColor; begin with CBBox.Canvas do begin bc:=Brush.color; Brush.color:=clRed; lrc.left:=rect.left; lrc.right:=20; lrc.Top:=rect.Top; lrc.Bottom:=rect.Bottom; rrc.Left:=20; rrc.Right:=rect.right; rrc.Top:=rect.Top; rrc.Bottom:=rect.bottom; FillRect(lrc); if odSelected in State then Brush.color:=clLime else Brush.color:=clWhite; FillRect(rrc); Brush.color:=bc; Brush.Style:=bsClear; TextOut(26,Index*CBBox.ItemHeight+2,CBBox.Items.Strings[Index]); end; end;
procedure TFrmEdit.ComboBox1DrawItem(Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState); var text : string; off : integer; i,N : integer; begin N :=0; for i :=0 to Combobox2.Items.Count - 1 do begin if ComboBox2.Items[i] = 'D' then N :=i - 2; end; ComboBox1.Canvas.FillRect( Rect ); if Index <= N then ImageList6.Draw(combobox1.canvas,Rect.left+2,Rect.top+2,0) else ImageList6.Draw(combobox1.canvas,Rect.left+2,Rect.top+2,1); text :=combobox1.items.Strings[Index]; off :=Trunc((Rect.bottom - Rect.top- combobox1.Canvas.TextHeight(text))/2); combobox1.Canvas.TextOut(Rect.left+imagelist6.width+2*2,Rect.top+off,text);
OnMeMeasureItem事件中设置高度
procedure TForm1.CBBoxDrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
var
lrc,rrc:TRect;
bc:TColor;
begin
with CBBox.Canvas do
begin
bc:=Brush.color;
Brush.color:=clRed;
lrc.left:=rect.left;
lrc.right:=20;
lrc.Top:=rect.Top;
lrc.Bottom:=rect.Bottom;
rrc.Left:=20;
rrc.Right:=rect.right;
rrc.Top:=rect.Top;
rrc.Bottom:=rect.bottom;
FillRect(lrc);
if odSelected in State then Brush.color:=clLime
else Brush.color:=clWhite;
FillRect(rrc);
Brush.color:=bc;
Brush.Style:=bsClear;
TextOut(26,Index*CBBox.ItemHeight+2,CBBox.Items.Strings[Index]);
end;
end;
Rect: TRect; State: TOwnerDrawState);
var
text : string;
off : integer;
i,N : integer;
begin
N :=0;
for i :=0 to Combobox2.Items.Count - 1 do
begin
if ComboBox2.Items[i] = 'D' then
N :=i - 2;
end; ComboBox1.Canvas.FillRect( Rect );
if Index <= N then
ImageList6.Draw(combobox1.canvas,Rect.left+2,Rect.top+2,0)
else
ImageList6.Draw(combobox1.canvas,Rect.left+2,Rect.top+2,1);
text :=combobox1.items.Strings[Index];
off :=Trunc((Rect.bottom - Rect.top- combobox1.Canvas.TextHeight(text))/2);
combobox1.Canvas.TextOut(Rect.left+imagelist6.width+2*2,Rect.top+off,text);
設定:ComboBoxEx1.Images := ImageList1;
把图标装入ImageList1中...