Button.Right 属性

定义

获取 Button 的右边缘与工作表的左边缘之间的距离(以磅为单位)。

public double Right { get; }

属性值

Button 的右边缘与工作表的左边缘之间的距离(以磅为单位)。

示例

下面的代码示例在单元格 B2 上添加控件 ButtonClick按钮的事件处理程序显示按钮的 RightBottom 属性的当前值。 在运行时调整列 B 或第 2 行的大小时,这些值会根据列或行的新大小而更改。

此示例适用于文档级自定义项。

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

注解

属性的值 Right 等于属性值和属性值之 LeftWidth

属性 Microsoft.Office.Tools.Excel.Controls.Button.Right 使用点,而 System.Windows.Forms.Control.Right 属性使用像素。

将值设置为负数或大于 12288 的数字不会引发异常,但会导致将控件设置为 0 和 12288 之间。

适用于