今天说说TNewCheckListBox类。
该类和ListBox差不多,只是下面的项可以用CheckBox或者RadioButton选择,是一种比较复杂的类型。
该类继承自
TCustomListBox,自身具有以下属性和函数:
TNewCheckListBox = class(TCustomListBox)
TNewCheckListBox = class(TCustomListBox)
function AddCheckBox(const ACaption, ASubItem: String; ALevel: Byte; AChecked, AEnabled, AHasInternalChildren, ACheckWhenParentChecked: Boolean; AObject: TObject): Integer;
function AddGroup(ACaption, ASubItem: String; ALevel: Byte; AObject: TObject): Integer;
function AddRadioButton(const ACaption, ASubItem: String; ALevel: Byte; AChecked, AEnabled: Boolean; AObject: TObject): Integer;
function CheckItem(const Index: Integer; const AOperation: TCheckItemOperation): Boolean;
property Checked[Index: Integer]: Boolean; read write;
property State[Index: Integer]: TCheckBoxState; read write;
property ItemCaption[Index: Integer]: String; read write;
property ItemEnabled[Index: Integer]: Boolean; read write;
property ItemLevel[Index: Integer]: Byte; read;
property ItemObject[Index: Integer]: TObject; read write;
property ItemSubItem[Index: Integer]: String; read write;
property AllowGrayed: Boolean; read write;
property Flat: Boolean; read write;
property MinItemHeight: Integer; read write;
property Offset: Integer; read write;
property OnClickCheck: TNotifyEvent; read write;
property BorderStyle: TBorderStyle; read write;
property Color: TColor; read write;
property Font: TFont; read write;
property Sorted: Boolean; read write;
property OnClick: TNotifyEvent; read write;
property OnDblClick: TNotifyEvent; read write;
property OnKeyDown: TKeyEvent; read write;
property OnKeyPress: TKeyPressEvent; read write;
property OnKeyUp: TKeyEvent; read write;
property ShowLines: Boolean; read write;
property WantTabs: Boolean; read write;
property RequireRadioSelection: Boolean; read write;
end
测试例子:
[code]
var
myPage:TWizardPage;
clb1, clb2: TNewCheckListBox;
lbl: TLabel;
i,index:Integer;
procedure clbClickCheck(Sender: TObject);
begin
lbl.Caption:='';
for i:=1 to 3 do
if clb1.Checked[i] then
lbl.Caption:=clb1.ItemCaption[i]+' ';
for i:=5 to 7 do
if clb1.Checked[i] then
lbl.Caption:=lbl.Caption+clb1.ItemCaption[i]+' ';
end;
procedure InitializeWizard();
begin
myPage:=CreateCustomPage(wpWelcome, '标题:自定义页面', '描述:这是我的自定义页面');
lbl:=TLabel.Create(myPage);
lbl.Parent:=myPage.Surface;
clb1 := TNewCheckListBox.Create(mypage);
clb1.Width := mypage.SurfaceWidth;
clb1.Top:=20;
clb1.Height := ScaleY(200);
clb1.Flat := True;
clb1.Parent := mypage.Surface;
clb1.AddCheckBox('操作系统', '', 0, True, True, False, True, nil);
clb1.AddRadioButton('Windows 2000', '', 1, False, True, nil);
clb1.AddRadioButton('Windows XP', '', 1, True, True, nil);
clb1.AddRadioButton('Windows 7', '', 1, False, True, nil);
clb1.AddCheckBox('可安装组件', '', 0, True, True, False, True, nil);
clb1.AddCheckBox('组件1', '', 1, True, True, False, True, nil);
clb1.AddCheckBox('组件2', '', 1, True, True, False, True, nil);
clb1.AddCheckBox('组件3', '', 1, False, True, False, True, nil);
clb1.OnClickCheck:=@clbClickCheck;
end;
其中的 procedure clbClickCheck将动态地根据所选项进行自动调整。