OptionButtonControl

OptionButtonControl class

OptionButton 控件可在有限的一组互斥选项中实现单一选择。

public class OptionButtonControl : MorphDataControl

特性

姓名描述
BackColor { get; set; }获取或设置控件的背景颜色。 默认值取决于控件的类型。
Caption { get; set; }获取或设置控件的 Caption 属性。 默认值为空字符串。
virtual ChildNodes { get; }获取直接子控件的集合。
Enabled { get; }返回真的如果控制处于启用状态。
ForeColor { get; set; }获取或设置控件的前景色。 默认值取决于控件的类型。
GroupName { get; set; }获取或设置指定一组互斥控件的字符串。 默认值为空字符串。
Height { get; set; }获取或设置控件的高度(以点为单位)。
IsForms2OleControl { get; }返回真的如果控件是Forms2OleControl.
Name { get; set; }获取或设置 ActiveX 控件的名称。
Selected { get; set; }获取或设置一个布尔值,表示OptionButtonControl是否被选中。
override Type { get; }获取 Forms 2.0 控件的类型。
Value { get; }获取通常代表控制状态的底层 Value 属性。 例如,选中的选项按钮的值为“1”,而未选中的选项按钮的值为“0”。 默认值为空字符串。
Width { get; set; }获取或设置控件的宽度(以点为单位)。

例子

显示如何选择单选按钮。

Document doc = new Document(MyDir + "Radio buttons.docx");

Shape shape1 = (Shape)doc.GetChild(NodeType.Shape, 0, true);
OptionButtonControl optionButton1 = (OptionButtonControl)shape1.OleFormat.OleControl;
// 取消选择选定的第一项。
optionButton1.Selected = false;

Shape shape2 = (Shape)doc.GetChild(NodeType.Shape, 1, true);
OptionButtonControl optionButton2 = (OptionButtonControl)shape2.OleFormat.OleControl;
// 选择第二个选项按钮。
optionButton2.Selected = true;

Assert.AreEqual(Forms2OleControlType.OptionButton, optionButton1.Type);
Assert.AreEqual(Forms2OleControlType.OptionButton, optionButton2.Type);

doc.Save(ArtifactsDir + "Shape.SelectRadioControl.docx");

也可以看看