to lizhao:
Supose you have the following LineTypes as ComboBox1's Items:
psClear, paSolid, psDash, psDot, psDashDot, paDashDotDot;
You can set ComboBox1.Style property to csOwnerDrawFixed.
After that, add the OnDrawItem event:
procedure TForm1.ComboBox1DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
var halfH: integer;
procedure DrawItemLine(ps: TPenStyle);
begin
ComboBox1.Canvas.Pen.Style := ps;
ComboBox1.Canvas.MoveTo( Rect.Left + 2, halfH );
ComboBox1.Canvas.LineTo( Rect.Right - 2, halfH );
end;
begin
ComboBox1.Canvas.Brush.Style := bsClear;
if odFocused in State then
begin
ComboBox1.Canvas.Pen.Color := clBlue;
end else
begin
ComboBox1.Canvas.pen.Color := clWhite;
end;
ComboBox1.Canvas.pen.Style := psSolid;
ComboBox1.Canvas.Rectangle( Rect.Left, Rect.Top, Rect.Right, Rect.Bottom);
ComboBox1.Canvas.pen.Color := clBlack;
halfH := Rect.Top + ComboBox1.Height div 2 - 2;
case index of
0: ComboBox1.Canvas.TextOut( Rect.Left+2, Rect.Top+2, '无线形');
1: DrawItemLine(psSolid);
2: DrawItemLine(psDash);
3: DrawItemLine(psDot);
4: DrawItemLine(psDashDot);
5: DrawItemLine(psDashDotDot);
end;
end;
Have a go of it!