Share via


Button.Right 屬性

取得 Button 的右邊緣和工作表的左邊緣之間的距離 (以點為單位)。

命名空間:  Microsoft.Office.Tools.Excel.Controls
組件:  Microsoft.Office.Tools.Excel.v4.0.Utilities (在 Microsoft.Office.Tools.Excel.v4.0.Utilities.dll 中)

語法

'宣告
Public ReadOnly Property Right As Double
public double Right { get; }

屬性值

型別:System.Double
Button 的右邊緣和工作表的左邊緣之間的距離 (以點為單位)。

備註

Right 屬性的值等於 Left 屬性值和 Width 屬性值的總和。

Button.Right 屬性使用點,而 Control.Right 屬性則使用像素。

將這個值設定為負數或是大於 12288 的數字時,並不會擲回例外狀況,但控制項還是會設定在 0 和 12288 之間。

範例

下列程式碼範例會在儲存格 B2 中加入 Button 控制項。 這個按鈕的 Click 事件處理常式會顯示按鈕的 Right 和 Bottom 屬性目前的值。 當在執行階段調整欄 B 或列 2 的大小時,這些值會隨著欄或列的新大小變更。

這是示範文件層級自訂的範例。

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

.NET Framework 安全性

請參閱

參考

Button 類別

Microsoft.Office.Tools.Excel.Controls 命名空間