Button.Delete Method (2007 System)
Deletes a dynamically created Button from the worksheet and removes it from the ControlCollection.
Namespace: Microsoft.Office.Tools.Excel.Controls
Assembly: Microsoft.Office.Tools.Excel.v9.0 (in Microsoft.Office.Tools.Excel.v9.0.dll)
Syntax
'Declaration
Public Function Delete As Object
'Usage
Dim instance As Button
Dim returnValue As Object
returnValue = instance.Delete()
public Object Delete()
public:
Object^ Delete()
public function Delete() : Object
Return Value
Type: System.Object
Remarks
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 worksheet at design time.
Examples
The following code example demonstrates a Button control that copies itself to the Clipboard when the user clicks it. The Click event handler of the button calls the CopyPicture method to copy the button to the Clipboard as a bitmap. The event handler also prompts the user to specify whether the original button should be deleted by calling the Delete method.
This example is for a document-level customization.
Private Sub CopyControlAsPicture()
Dim CopyButton As Microsoft.Office.Tools.Excel.Controls.Button = _
Me.Controls.AddButton(Me.Range("B2", "D3"), "CopyButton")
CopyButton.Text = "Click to copy this control"
AddHandler CopyButton.Click, AddressOf copyButtonPicture_Click
End Sub
Private Sub CopyButtonPicture_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim ClickedButton As Microsoft.Office.Tools.Excel.Controls.Button = _
CType(sender, Microsoft.Office.Tools.Excel.Controls.Button)
If False = CBool( _
ClickedButton.CopyPicture(Excel.XlPictureAppearance.xlScreen, _
Excel.XlCopyPictureFormat.xlBitmap)) Then
MsgBox("CopyPicture failed")
End If
End Sub
private void CopyControlAsPicture()
{
Microsoft.Office.Tools.Excel.Controls.Button copyButton =
this.Controls.AddButton(this.Range["B2", "D3"],
"copyButton");
copyButton.Text = "Click to copy this control";
copyButton.Click += new EventHandler(copyButtonPicture_Click);
}
void copyButtonPicture_Click(object sender, EventArgs e)
{
Microsoft.Office.Tools.Excel.Controls.Button clickedButton =
(Microsoft.Office.Tools.Excel.Controls.Button)sender;
if (false == (bool)clickedButton.CopyPicture(
Excel.XlPictureAppearance.xlScreen,
Excel.XlCopyPictureFormat.xlBitmap))
{
MessageBox.Show("CopyPicture failed");
}
}
.NET Framework Security
- Full trust for the immediate caller. This member cannot be used by partially trusted code. For more information, see Using Libraries from Partially Trusted Code.