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[i].ClassType = TCheckBox) then
    begin
      TCheckBox(Panel1.Controls[i]).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[i].ClassType = TCheckBox) then
    begin
      TCheckBox(Panel1.Controls[i]).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[i].ClassType = TCheckBox) then
    begin
      if TCheckBox(Panel1.Controls[i]).Checked then
        TCheckBox(Panel1.Controls[i]).Checked := false
      else
        TCheckBox(Panel1.Controls[i]).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[i] := 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[i] = True then
      ShowMessage(CheckListBox1.Items[i]);
    //写入到文件
  end;
end;
 
procedure TForm1.Button6Click(Sender: TObject);       //清空,便于加入新的一组
begin
  CheckListBox1.Items.Clear;
end;
 
end.

相关阅读 >>

Delphi 请求时间,为当前时间,数值为1970-01-01以来的毫秒数

Delphi 域名转ip并判断ip是否可以联通 复制代码

Delphi 枚举数组

两种方法用Delphi实现域名转ip地址---用nmhttp控件和winsock

Delphi webservices 字节数组 base64编码

Delphi之猥琐的webserver实现

Delphi用命令行加载驱动

Delphi 开启内存泄漏报告模式

Delphi中读取硬盘的物理序列号

Delphi 枚举所有电脑磁盘

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...

    暂无评论...