共用方式為


Button.TopLeftCell Property

Definition

Gets a Range object that represents the cell that lies under the upper-left corner of the Button.

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

Property Value

A Range object that represents the cell that lies under the upper-left corner of the Button.

Examples

The following code example uses the TopLeftCell and BottomRightCell properties to get the top left and bottom right cells in relation to a Button control. The Click event handler of the button colors the borders of the top left and bottom right cell red.

This example is for a document-level customization.

private void MarkCornerCells()
{
    Microsoft.Office.Tools.Excel.Controls.Button button1 =
        this.Controls.AddButton(65, 45, 100, 25,
        "button1");
    button1.Text = "Click to highlight corners.";
    button1.Click += new EventHandler(button1_Click);
}

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

    clickedButton.BottomRightCell.Borders.Color = 
        ColorTranslator.ToOle(Color.Red);
    clickedButton.TopLeftCell.Borders.Color =
        ColorTranslator.ToOle(Color.Red);
}
Private Sub MarkCornerCells()
    Dim CornerButton As Microsoft.Office.Tools.Excel.Controls.Button = _
        Me.Controls.AddButton(65, 45, 100, 25, "CornerButton")
    CornerButton.Text = "Click to highlight corners."
    AddHandler CornerButton.Click, AddressOf CornerButton_Click
End Sub

Private Sub CornerButton_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.BottomRightCell.Borders.Color = _
        ColorTranslator.ToOle(Color.Red)
    ClickedButton.TopLeftCell.Borders.Color = _
        ColorTranslator.ToOle(Color.Red)
End Sub

Applies to