ControlCollection.Remove 方法 (String)

ControlCollection 实例中移除具有指定名称的控件。

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

语法

声明
Function Remove ( _
    name As String _
) As Boolean
bool Remove(
    string name
)

参数

返回值

类型:System.Boolean

备注

无法从 ControlCollection 实例中移除设计时添加的控件。只能使用 Remove 方法移除在运行时添加的控件。

示例

下面的代码示例向工作表中添加一个 Button 控件和一个 MonthCalendar 控件。单击该按钮时,代码移除 MonthCalendar 控件。

Private Sub ExcelControlRemove()

    Dim Button1 As Microsoft.Office.Tools.Excel. _
        Controls.Button = Me.Controls.AddButton( _
        0, 0, 56.25, 17.25, "Button1")
    Dim MonthCalendar1 As Microsoft.Office.Tools. _
        Excel.Controls.MonthCalendar = Me.Controls. _
        AddMonthCalendar(0, 20, 75, 15, "MonthCalendar1")

    Button1.Text = "Remove"

    AddHandler Button1.Click, AddressOf Button1_Click

End Sub
Private Sub Button1_Click(ByVal sender As Object, ByVal e As _
    EventArgs)

    Me.Controls.Remove("MonthCalendar1")

End Sub
private void ExcelControlRemove()
{

    Microsoft.Office.Tools.Excel.Controls.Button button1 =
        this.Controls.AddButton(0, 0, 56.25, 17.25,
        "button1");
    Microsoft.Office.Tools.Excel.Controls.MonthCalendar
         monthCalendar1 = this.Controls.AddMonthCalendar(
         0, 20, 75, 15, "monthCalendar1");
    button1.Text = "Remove";
    button1.Click += new EventHandler(button1_Click);

}

void button1_Click(object sender, EventArgs e)
{
    this.Controls.Remove("monthCalendar1");
}

.NET Framework 安全性

请参见

参考

ControlCollection 接口

Remove 重载

Microsoft.Office.Tools.Excel 命名空间