TCheckGroup/zh CN: what changed
Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.
| Old | New | Line | |
|---|---|---|---|
| 1 | 1 | A **TCheckGroup**  is a control that comprises a group of [[TCheckBox]] items physically and logically grouped together on a container component. | |
| 2 | 2 | ||
| 3 | 3 | ## 用法 | |
| 4 | 4 | ||
| 5 | 5 | To 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选项卡]]上选择它,并在窗体上单击,将其加入到窗口中。 | |
| 6 | 6 | ||
| 7 | 7 | ### 小例子 | |
| 8 | 8 | ||
| 9 | 9 | 这个例子改变窗体的背景颜色。这个颜色是通过添加单独的颜色组件来确定的。 | |
| 10 | 10 | ||
| 11 | 11 | - 创建一个新的应用程序,并在您的窗体上放置一个TCheckGroup组件 | |
| 12 | 12 | - in the object inspector change the property *Name* of *CheckGroup1* to *cgRed* and the caption to *Red* | |
| 13 | 13 | ||
| 14 | 14 | 在对象检查器中修改*CheckGroup1*的属性*Name*为*cgRed*,标题为*Red* | |
| 15 | 15 | ||
| 16 | 16 | - 为“cgRed”添加复选框: | |
| 17 | 17 | - 在对象检查器中选择“cgRed”的属性“Items” | |
| 18 | 18 | - 点击按钮\[…\],则打开字符串编辑器 | |
| 19 | 19 | - 每行输入一个数字,“1 2 4 8 16 32 64 128”,然后按“OK”键完成输入 | |
| 20 | 20 | - 在*cgRed*上单击右键再单击*Copy*复制这个 TCheckGroup | |
| 21 | 21 | - 在窗体的空白处单击右键选择*insert*, 这将创建名为“cgRed1”的TCheckGroup | |
| 22 | 22 | - 现在改变*Name* 属性为 *cgGreen* , *Caption* 属性改为 *Green* | |
| 23 | 23 | - 插入一个TCheckGroup并更改名称为“cgBlue”和标题为“Blue” | |
| 24 | 24 | - 只要点击复选框,颜色就会改变: | |
| 25 | 25 | - 在对象检查器中通过点击在事件“OnItemClick”旁边\[…\]按钮创建" cgRed "的" OnItemClick "事件处理程序 | |
| 26 | 26 | - 选择“cgGreen”和“cgBlue”也是这个事件处理程序,通过选择每个CheckGroup组件的事件“OnItemClick”旁边的组合框,选择“cgRedItemClick” | |
| 27 | 27 | - 在事件处理程序中编写以下代码: | |
| 28 | 28 | ||
| 29 | 29 | ``` pascal | |
| 30 | 30 | procedure TForm1.cgRedItemClick(Sender: TObject; Index: integer); | |
| 31 | 31 | var | |
| 32 | 32 | i, c: Integer; | |
| 33 | 33 | begin | |
| 34 | 34 | c := $000000; // 最开始颜色是黑色的 | |
| 35 | 35 | for i:=0 to 7 do begin // test Items 0..7 of all Checkgroups | |
| 36 | 36 | if cgRed.Checked[i] then c := c + 1 shl i; // 红色的量 $000000..$0000FF | |
| 37 | 37 | if cgGreen.Checked[i] then c := c + 1 shl (i + 8); // 绿色的量 $000000..$00FF00 | |
| 38 | 38 | if cgBlue.Checked[i] then c := c + 1 shl (i + 16); // 蓝色的量 $000000..$FF0000 | |
| 39 | 39 | end; | |
| 40 | 40 | Color := c; | |
| 41 | 41 | end; | |
| 42 | 42 | ``` | |
| 43 | 43 | ||
| 44 | 44 | - start your program, it could look like: | |
| 45 | 45 | ||
| 46 | - | ||
| 47 | - | ||
| 48 | - | ||
| 49 | - | ||
| 46 | + |  | |
| 50 | 47 | ||
| 51 | 48 | ## 访问复选框 | |
| 52 | 49 | ||
| 53 | 50 | TCheckGroup中的每个项目都有一个Checked属性,可以将它们全部设置为Checked | |
| 54 | 51 | ||
| 55 | 52 | ``` pascal | |
| 56 | 53 | for i := 0 to MyCheckGroup.items.Count-1 do // check all the categories we found. | |
| 57 | 54 | MyCheckGroup.Checked[i] := true; | |
| 58 | 55 | ``` | |
| 59 | 56 | ||
| 60 | 57 | 您可以使用TCheckGroup在运行时添加项目。Items,它是TStrings列表。要向集合中添加一个新的复选框,只需执行MyCheckGroup.Items.add('CheckThis');类似地,要删除所有项,清空列表,MyCheckGroup.Items.clear; | |
| 61 | 58 | ||
| 62 | 59 | ## See also | |
| 63 | 60 | ||
| 64 | 61 | - [[doc:lcl/extctrls/tcheckgroup.html|TCheckGroup doc]] | |
| 65 | 62 | - [[TCheckBox]] | |
| 66 | 63 | - [[TGroupBox]] | |
| 67 | 64 | ||
| 68 | 65 | --- | |
| 69 | 66 | *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).* |
