2行表示のリストを作成するには、OnDrawItem イベントと OnMeasureItem イベントを使用します。
以下のステップで行います。
- OnMeasureItemイベントで2行分表示するための高さを確保します。
- OnDrawItemイベントでCanvasにテキストを描画します。
- Styleを「lbOwnerDrawVariable」に変更します。(自分で中身を書き換えますよ!という定義)
この方法は、TCheckListBox でも使用できます。(2行目が固定で“2行目”になっているので、お好みに合わせて変更してください。 また、Styleを「lbOwnerDrawVariable」に変更するのを忘れないでください。)
procedure TForm1.ListBox1MeasureItem(Control: TWinControl; Index: Integer; var Height: Integer); begin Height := -1 * TListBox(Control).Font.Height * 2 + 6; // リストボックスの1項目の高さを設定 end; procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState); begin with TListBox(Control) do begin Canvas.FillRect(Rect); Canvas.TextOut(Rect.Left + 2, Rect.Top + 2, Items[Index]); // 1行目 Canvas.TextOut(Rect.Left + 2, Rect.Top + (-1 * Font.Height) + 4, '2行目'); // 2行目 end; end;
以下のコメントは、その投稿者が所有するものでサイト管理者はコメントに関する責任を負いません。