Share via


Button.TopLeftCell Property (2007 System)

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

Namespace:  Microsoft.Office.Tools.Excel.Controls
Assembly:  Microsoft.Office.Tools.Excel.v9.0 (in Microsoft.Office.Tools.Excel.v9.0.dll)

Syntax

'Declaration
Public ReadOnly Property TopLeftCell As Range
'Usage
Dim instance As Button 
Dim value As Range 

value = instance.TopLeftCell
public Range TopLeftCell { get; }
public:
property Range^ TopLeftCell {
    Range^ get ();
}
public function get TopLeftCell () : Range

Property Value

Type: Range
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 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
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);
}

.NET Framework Security

See Also

Reference

Button Class

Button Members

Microsoft.Office.Tools.Excel.Controls Namespace