[BlueLeaf1336]> PROGRAM> Natural Born Junk>
| history | TOP |
2002/10/30:作成
| memo | TOP |
オーナードローのやり方が最初全然わからずに弱ったので記念に。
| code | TOP |
(*
=================================================
オーナードローのサンプル ComboBox版
ComboBox1.ItemHeight := 18;
ComboBox1.Style := csOwnerDrawFixed;
=================================================
*)
procedure TForm1.ComboBox1DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
var
ComboBox: TComboBox;
ComboCanvas: TCanvas;
TextItem: string;
PosX, PosY: integer;
begin
//キャスト
ComboBox := TComboBox(Control);
ComboCanvas := ComboBox.Canvas;
TextItem := ComboBox.Items[Index];
//位置揃え
PosX := 5;
PosY := (ComboBox.ItemHeight - ComboCanvas.TextHeight(TextItem)) div 2;
//背景色決定
if odSelected in State then
begin
ComboCanvas.Brush.Color := RGB(153, 204, 255);
end else
begin
ComboCanvas.Brush.Color := clWindow;
end;
//塗りつぶし。どれでもそこそこな感じになります。
// ComboCanvas.Rectangle(Classes.Rect(Rect.TopLeft, Point(Rect.Right + 1, Rect.Bottom + 1)));
// ComboCanvas.Rectangle(Classes.Rect(Point(Rect.Left - 1, Rect.Top - 1), Rect.BottomRight));
// ComboCanvas.FillRect(Classes.Rect(Rect.TopLeft, Point(Rect.Right + 1, Rect.Bottom + 1)));
// ComboCanvas.FillRect(Classes.Rect(Point(Rect.Left - 1, Rect.Top - 1), Rect.BottomRight));
ComboCanvas.FillRect(Rect);
// ComboCanvas.Rectangle(Rect);
//書き出し
ComboCanvas.Font.Color := clBlack;
ComboCanvas.TextOut(Rect.Left + PosX, Rect.Top + PosY, TextItem);
end;
| EOF | TOP |