Button.Delete 方法

从该文档中删除动态创建的 Button 并将其从 ControlCollection 中移除。

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

语法

声明
Public Sub Delete
public void Delete()

备注

此方法只应与以编程方式在运行时创建的 Button 一起使用。如果对设计时添加到文档中的 Button 调用此方法,将引发异常。

示例

下面的代码示例演示当用户单击 Button 控件时,它删除自身。该按钮的 Click 事件处理程序调用 Delete 方法删除按钮。

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

Private Sub DeleteControl()
    Dim DeleteButton As Microsoft.Office.Tools.Word.Controls.Button = _
        Me.Controls.AddButton(25, 75, 80, 30, "DeleteButton")
    DeleteButton.Text = "Click to delete"
    AddHandler DeleteButton.Click, AddressOf DeleteButton_Click
End Sub

' Delete the clicked button.
Private Sub DeleteButton_Click(ByVal sender As Object, ByVal e As EventArgs)
    Dim ClickedButton As Microsoft.Office.Tools.Word.Controls.Button = _
        CType(sender, Microsoft.Office.Tools.Word.Controls.Button)

    ClickedButton.Delete()
End Sub
private void DeleteControl()
{
    Microsoft.Office.Tools.Word.Controls.Button deleteButton =
        this.Controls.AddButton(25, 75, 80, 30, "deleteButton");
    deleteButton.Text = "Click to delete";
    deleteButton.Click += new EventHandler(deleteButton_Click);
}

// Delete the clicked button.
void deleteButton_Click(object sender, EventArgs e)
{
    Microsoft.Office.Tools.Word.Controls.Button clickedButton =
        (Microsoft.Office.Tools.Word.Controls.Button)sender;

    clickedButton.Delete();
}

.NET Framework 安全性

请参见

参考

Button 类

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