Button.ShapeRange Property

Definition

Gets a ShapeRange object that represents the Button.

public Microsoft.Office.Interop.Excel.ShapeRange ShapeRange { get; }

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

Applies to