// TComboBox example of lines of various widths and styles. // efg, December 2000. // Change ComboBox1.Style to csOwnerDrawFixed and define CombBoxBox1DrawItem // as shown below. Add eight "Items" (I used 1, 2, 3, ..., 8) to the // TComboBox1. Add five "Items" to the TComboBox2. // A geometric pen is used since the default rounded ends for line widths > 1 // look very bad. unit ScreenGeometricPen; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) ComboBox1: TComboBox; ComboBox2: TComboBox; procedure ComboBox1DrawItem(Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState); procedure FormCreate(Sender: TObject); procedure ComboBox2DrawItem(Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.DFM} procedure TForm1.ComboBox1DrawItem(Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState); VAR BrushInfo: TLogBrush; i1 : INTEGER; i2 : INTEGER; begin WITH BrushInfo DO BEGIN lbStyle := BS_SOLID; lbColor := clBlack; lbHatch := 0 END; (Control AS TComboBox).Canvas.Pen.Handle := ExtCreatePen(PS_GEOMETRIC OR PS_ENDCAP_SQUARE OR PS_JOIN_MITER, index+1, BrushInfo, 0, NIL); WITH (Control AS TComboBox).Canvas DO BEGIN i1 := MulDiv(rect.Left + rect.Right, 1, 5); i2 := MulDiv(rect.Left + rect.Right, 4, 5); MoveTo(i1, (rect.Top + rect.Bottom) DIV 2); LineTo(i2, (rect.Top + rect.Bottom) DIV 2) END end; procedure TForm1.FormCreate(Sender: TObject); begin ComboBox1.ItemIndex := 0; ComboBox2.ItemIndex := 0; end; procedure TForm1.ComboBox2DrawItem(Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState); VAR BrushInfo: TLogBrush; i1 : INTEGER; i2 : INTEGER; PenStyle : DWORD; begin WITH BrushInfo DO BEGIN lbStyle := BS_SOLID; lbColor := clBlack; lbHatch := 0 END; PenStyle := PS_GEOMETRIC OR PS_ENDCAP_SQUARE OR PS_JOIN_MITER; CASE index OF 0: PenStyle := PenStyle + PS_SOLID; 1: PenStyle := PenStyle + PS_DASH; 2: PenStyle := PenStyle + PS_DOT; 3: PenStyle := PenStyle + PS_DASHDOT; 4: PenStyle := PenStyle + PS_DASHDOTDOT; END; (Control AS TComboBox).Canvas.Pen.Handle := ExtCreatePen(PenStyle, 3, BrushInfo, 0, NIL); WITH (Control AS TComboBox).Canvas DO BEGIN i1 := MulDiv(rect.Left + rect.Right, 1, 5); i2 := MulDiv(rect.Left + rect.Right, 4, 5); MoveTo(i1, (rect.Top + rect.Bottom) DIV 2); LineTo(i2, (rect.Top + rect.Bottom) DIV 2) END end; end.