Sign in Join
Wiki copytemporary

TCheckGroup/zh CN: what changed

Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.

OldNewLine
11A **TCheckGroup** ![](/wiki-images/1/1b/Tcheckgroup.png) is a control that comprises a group of [[TCheckBox]] items physically and logically grouped together on a container component.
22
33## 用法
44
55To use a TCheckGroup on a [[TForm|form]], you can simply select it on the [[Standard tab]] of the [[Component Palette]] and place it by clicking on the form. 要在[[TForm|窗体]]上使用TCheckGroup,您可以简单地在[[Component Palette|控件面板]]的[[Standard tab|Standard选项卡]]上选择它,并在窗体上单击,将其加入到窗口中。
66
77### 小例子
88
99这个例子改变窗体的背景颜色。这个颜色是通过添加单独的颜色组件来确定的。
1010
1111- 创建一个新的应用程序,并在您的窗体上放置一个TCheckGroup组件
1212- in the object inspector change the property *Name* of *CheckGroup1* to *cgRed* and the caption to *Red*
1313
1414在对象检查器中修改*CheckGroup1*的属性*Name*为*cgRed*,标题为*Red*
1515
1616- 为“cgRed”添加复选框:
1717 - 在对象检查器中选择“cgRed”的属性“Items”
1818 - 点击按钮\[…\],则打开字符串编辑器
1919 - 每行输入一个数字,“1 2 4 8 16 32 64 128”,然后按“OK”键完成输入
2020- 在*cgRed*上单击右键再单击*Copy*复制这个 TCheckGroup
2121- 在窗体的空白处单击右键选择*insert*, 这将创建名为“cgRed1”的TCheckGroup
2222- 现在改变*Name* 属性为 *cgGreen* , *Caption* 属性改为 *Green*
2323- 插入一个TCheckGroup并更改名称为“cgBlue”和标题为“Blue”
2424- 只要点击复选框,颜色就会改变:
2525 - 在对象检查器中通过点击在事件“OnItemClick”旁边\[…\]按钮创建" cgRed "的" OnItemClick "事件处理程序
2626 - 选择“cgGreen”和“cgBlue”也是这个事件处理程序,通过选择每个CheckGroup组件的事件“OnItemClick”旁边的组合框,选择“cgRedItemClick”
2727 - 在事件处理程序中编写以下代码:
2828
2929``` pascal
3030procedure TForm1.cgRedItemClick(Sender: TObject; Index: integer);
3131var
3232 i, c: Integer;
3333begin
3434 c := $000000; // 最开始颜色是黑色的
3535 for i:=0 to 7 do begin // test Items 0..7 of all Checkgroups
3636 if cgRed.Checked[i] then c := c + 1 shl i; // 红色的量 $000000..$0000FF
3737 if cgGreen.Checked[i] then c := c + 1 shl (i + 8); // 绿色的量 $000000..$00FF00
3838 if cgBlue.Checked[i] then c := c + 1 shl (i + 16); // 蓝色的量 $000000..$FF0000
3939 end;
4040 Color := c;
4141end;
4242```
4343
4444- start your program, it could look like:
4545
46-<figure>
47-<img src="ExampleTCheckGroup.png" title="ExampleTCheckGroup.png" />
48-<figcaption>ExampleTCheckGroup.png</figcaption>
49-</figure>
46+![](/wiki-images/c/ca/ExampleTCheckGroup.png)
5047
5148## 访问复选框
5249
5350TCheckGroup中的每个项目都有一个Checked属性,可以将它们全部设置为Checked
5451
5552``` pascal
5653for i := 0 to MyCheckGroup.items.Count-1 do // check all the categories we found.
5754 MyCheckGroup.Checked[i] := true;
5855```
5956
6057您可以使用TCheckGroup在运行时添加项目。Items,它是TStrings列表。要向集合中添加一个新的复选框,只需执行MyCheckGroup.Items.add('CheckThis');类似地,要删除所有项,清空列表,MyCheckGroup.Items.clear;
6158
6259## See also
6360
6461- [[doc:lcl/extctrls/tcheckgroup.html|TCheckGroup doc]]
6562- [[TCheckBox]]
6663- [[TGroupBox]]
6764
6865---
6966*From the Free Pascal wiki, page "TCheckGroup/zh CN", as it stood on 2023-02-04 after a change by Clzwf, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*

Back to history