Udostępnij za pośrednictwem


Button.Right Property

Definition

Gets the distance, in points, between the right edge of the Button and the left edge of the worksheet.

public:
 property double Right { double get(); };
public double Right { get; }
member this.Right : double
Public ReadOnly Property Right As Double

Property Value

The distance, in points, between the right edge of the Button and the left edge of the worksheet.

Examples

The following code example adds a Button control on cell B2. The Click event handler of the button displays the current values of the Right and Bottom properties of the button. When column B or row 2 is resized at run time, these values change according to the new size of the column or row.

This example is for a document-level customization.

private void DisplayRightAndBottom()
{
    Microsoft.Office.Tools.Excel.Controls.Button pointButton =
        this.Controls.AddButton(this.Range["B2", "C3"],
        "pointButton");
    pointButton.Text = "Click to display location";
    pointButton.Click += new EventHandler(pointButton_Click);
}

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

    MessageBox.Show("Right is: " + clickedButton.Right.ToString() +
        "; Bottom is: " + clickedButton.Bottom.ToString());
}
Private Sub DisplayRightAndBottom()
    Dim PointButton As Microsoft.Office.Tools.Excel.Controls.Button = _
        Me.Controls.AddButton(Me.Range("B2", "C3"), "PointButton")
    PointButton.Text = "Click to display location"
    AddHandler PointButton.Click, AddressOf PointButton_Click
End Sub

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

    MsgBox("Right is: " & ClickedButton.Right.ToString() & _
        "; Bottom is: " & ClickedButton.Bottom.ToString())
End Sub

Remarks

The value of the Right property is equal to the sum of the Left property value and the Width property value.

The Microsoft.Office.Tools.Excel.Controls.Button.Right property uses points, whereas System.Windows.Forms.Control.Right property uses pixels.

Setting the value to a negative number or a number higher than 12288 does not throw an exception but results in the control being set between 0 and 12288.

Applies to