Button.ShapeRange Property

Definition

Gets a ShapeRange object that represents the Button.

public:
 property Microsoft::Office::Interop::Excel::ShapeRange ^ ShapeRange { Microsoft::Office::Interop::Excel::ShapeRange ^ get(); };
public Microsoft.Office.Interop.Excel.ShapeRange ShapeRange { get; }
member this.ShapeRange : Microsoft.Office.Interop.Excel.ShapeRange
Public ReadOnly Property ShapeRange As ShapeRange

Property Value

A ShapeRange object that represents the Button.

Examples

The following code example adds a Button control to the current worksheet. The Click event handler for this button uses the ShapeRange property to get a Microsoft.Office.Interop.Excel.ShapeRange for the button, and then increases the width of this Microsoft.Office.Interop.Excel.ShapeRange by 10 points. Although the event handler only adjusts the width of the button, the height also changes automatically so that the control retains the original proportion.

This example is for a document-level customization.

private void UseShapeRange()
{
    Microsoft.Office.Tools.Excel.Controls.Button growingButton =
        this.Controls.AddButton(this.Range["B2", "C3"],
        "growingButton");
    growingButton.Text = "Click to grow button";
    growingButton.Click +=
        new EventHandler(growingButton_Click);
}

void growingButton_Click(object sender, EventArgs e)
{
    Microsoft.Office.Tools.Excel.Controls.Button clickedButton =
        (Microsoft.Office.Tools.Excel.Controls.Button)sender;

    clickedButton.ShapeRange.Width += 10;
}
Private Sub UseShapeRange()
    Dim GrowingButton As Microsoft.Office.Tools.Excel.Controls.Button = _
        Me.Controls.AddButton(Me.Range("B2", "C3"), "GrowingButton")
    GrowingButton.Text = "Click to grow button"
    AddHandler GrowingButton.Click, AddressOf GrowingButton_Click
End Sub

Private Sub GrowingButton_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)

    ClickedButton.ShapeRange.Width += 10
End Sub

Applies to