首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

ListBox控件能否添加其它控件?解决方法

2012-04-07 
ListBox控件能否添加其它控件?请教大家一个问题,ListBox控件能否添加其它控件?比如添加几个按钮,进度条之

ListBox控件能否添加其它控件?
请教大家一个问题,ListBox控件能否添加其它控件?
比如添加几个按钮,进度条之类的这样的控件。
目前能实现添加文字和图标

[解决办法]
画上去

Delphi(Pascal) code
unit Unit1;interfaceuses  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,  Dialogs, StdCtrls;type  TForm1 = class(TForm)    lst1: TListBox;    chk1: TCheckBox;    procedure lst1DrawItem(Control: TWinControl; Index: Integer;      Rect: TRect; State: TOwnerDrawState);    procedure FormCreate(Sender: TObject);  private    { Private declarations }    chks : array of TCheckBox;  public    { Public declarations }  end;var  Form1: TForm1;implementation{$R *.dfm}procedure TForm1.lst1DrawItem(Control: TWinControl; Index: Integer;  Rect: TRect; State: TOwnerDrawState);var  tempRect : TRect;begin  tempRect := Rect;  tempRect.Left := 20;  TListBox(Control).Canvas.TextRect(tempRect,tempRect.Left,tempRect.Top,'画上去');  chks[Index].Left := Rect.Left;  chks[Index].Top := Rect.Top;end;procedure TForm1.FormCreate(Sender: TObject);var  I : Integer;begin  SetLength(chks,lst1.Items.Count);  for I := Low(chks) to High(chks) do  begin    chks[I] := TCheckBox.Create(Self);    chks[I].Width := 20;    chks[I].Height := 20;    chks[I].Parent := lst1;  end;end;end.
[解决办法]
DrawItem事件中,setbounds你的控件
[解决办法]
画,DrawItem

1樓正確
[解决办法]
可以响应。这个需要你编码控制坐标信息的。

热点排行