Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.

Button.Delete Method

Deletes a dynamically created Button from the document and removes it from the ControlCollection.

Namespace: Microsoft.Office.Tools.Word.Controls
Assembly: Microsoft.Office.Tools.Word (in microsoft.office.tools.word.dll)

public void Delete ()

This method should only be used with a Button that is created programmatically at run time. An exception is thrown if you call this method on a Button that is added to the document at design time.

The following code example demonstrates a Button control that deletes itself when the user clicks it. The Click event handler of the button calls the Delete method to delete the button.

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();
}

Show:
© 2015 Microsoft