Button.Select 方法 (Object)

选择 Button

命名空间:  Microsoft.Office.Tools.Excel.Controls
程序集:  Microsoft.Office.Tools.Excel.v4.0.Utilities(在 Microsoft.Office.Tools.Excel.v4.0.Utilities.dll 中)

语法

声明
Public Function Select ( _
    Replace As Object _
) As Object
public Object Select(
    Object Replace
)

参数

  • Replace
    类型:System.Object
    如果设置为 true,则用 Button 替换当前选中的内容;如果设置为 false,则扩展当前选择范围,使之包含以前选择的所有对象和 Button

返回值

类型:System.Object
在 Excel 2010 中,此方法将返回一个空引用(在 Visual Basic 中为 Nothing);否则,此方法将返回 true。

备注

可选参数

有关可选参数的信息,请参见Office 解决方案中的可选参数

示例

下面的代码示例向工作表中添加两个 Button 控件,然后通过使用 Select 方法以编程方式选中这两个按钮。 第一次调用 Select 时传入 true 作为 Replace 参数的值,以确保工作表上只选中第一个按钮。 第二次调用 Select 时传入 false,以使两个按钮都被选中。

此示例针对的是文档级自定义项。

Private Sub SelectControl()
    Dim SelectButton1 As Microsoft.Office.Tools.Excel.Controls.Button = _
        Me.Controls.AddButton(Me.Range("B2", "C3"), "SelectButton1")
    SelectButton1.Text = "Button 1"

    Dim SelectButton2 As Microsoft.Office.Tools.Excel.Controls.Button = _
        Me.Controls.AddButton(Me.Range("B4", "C5"), "SelectButton2")
    SelectButton2.Text = "Button 2"

    SelectButton1.Select(True)
    SelectButton2.Select(False)
End Sub
private void SelectControl()
{
    Microsoft.Office.Tools.Excel.Controls.Button selectButton1 =
        this.Controls.AddButton(this.Range["B2", "C3"],
        "selectButton1");
    selectButton1.Text = "Button 1";

    Microsoft.Office.Tools.Excel.Controls.Button selectButton2 =
        this.Controls.AddButton(this.Range["B4","C5"],
        "selectButton2");
    selectButton2.Text = "Button 2";

    selectButton1.Select(true);
    selectButton2.Select(false);
}

.NET Framework 安全性

请参见

参考

Button 类

Select 重载

Microsoft.Office.Tools.Excel.Controls 命名空间