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