Delphi动态复选框源码:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, CheckLst;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
Panel1: TPanel;
CheckListBox1: TCheckListBox;
CheckBox1: TCheckBox;
CheckBox2: TCheckBox;
CheckBox3: TCheckBox;
CheckBox4: TCheckBox;
CheckBox5: TCheckBox;
Button4: TButton;
Button5: TButton;
Button6: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure Button5Click(Sender: TObject);
procedure Button6Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject); //全选
var
i: Integer;
begin
for i := 0 to Panel1.ControlCount - 1 do
begin
if (Panel1.Controls.ClassType = TCheckBox) then
begin
TCheckBox(Panel1.Controls).Checked := True;
end;
end;
end;
procedure TForm1.Button2Click(Sender: TObject); //取消全部选择
var
i: Integer;
begin
for i := 0 to Panel1.ControlCount - 1 do
begin
if (Panel1.Controls.ClassType = TCheckBox) then
begin
TCheckBox(Panel1.Controls).Checked := False;
end;
end;
end;
procedure TForm1.Button3Click(Sender: TObject); //反选
var
i: Integer;
begin
for i := 0 to Panel1.ControlCount - 1 do
begin
if (Panel1.Controls.ClassType = TCheckBox) then
begin
if TCheckBox(Panel1.Controls).Checked then
TCheckBox(Panel1.Controls).Checked := false
else
TCheckBox(Panel1.Controls).Checked := True;
end;
end;
end;
procedure TForm1.Button4Click(Sender: TObject); //全选
var
i: integer;
begin
for i := 0 to CheckListBox1.Items.Count - 1 do
begin
CheckListBox1.Checked := True; //反选设置为False
//写入到文件
end;
end;
procedure TForm1.Button5Click(Sender: TObject);
var
i: integer;
begin
for i := 0 to CheckListBox1.Items.Count - 1 do
begin
if CheckListBox1.Checked = True then
ShowMessage(CheckListBox1.Items);
//写入到文件
end;
end;
procedure TForm1.Button6Click(Sender: TObject); //清空,便于加入新的一组
begin
CheckListBox1.Items.Clear;
end;
end.
感谢分享,楼主辛苦了。。 写的不错么,一看就是下了一番功夫的,支持楼主!楼主 Delphi Xe 10.3 RIO 出来了,晓得不 这里用D有真少 恭喜调试成功,delphi做为VB杀手,win平台上个人RAD开发还是最好的选择! 感谢分享,Delphi挺实用的 Delphi挺好用 看着就熟悉和亲切 很高兴还有人用Delphi,这个源码应该是研究性的,不是实用性的。
页:
[1]
2