Button.Border 屬性

取得 Border,表示 Button 的邊框。

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

語法

'宣告
Public ReadOnly Property Border As Border
public Border Border { get; }

屬性值

型別:Microsoft.Office.Interop.Excel.Border
Border ,表示 Button 的邊框。

範例

下列程式碼範例會將 Button 控制項加入至工作表,然後使用 Border 屬性將儲存格的邊框變為綠色。 這個按鈕的 Click 事件處理常式會使用 Visible 屬性隱藏按鈕,然後提示使用者選擇要取消隱藏按鈕,或讓按鈕保持隱藏狀態。

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

Private Sub AlterControlAppearance()
    Dim HideButton As Microsoft.Office.Tools.Excel.Controls.Button = _
        Me.Controls.AddButton(Me.Range("B2", "C3"), "HideButton")

    HideButton.Text = "Click to hide"
    HideButton.Border.Color = ColorTranslator.ToOle(Color.Green)
    AddHandler HideButton.Click, AddressOf hideButton_Click
End Sub

Private Sub HideButton_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.Visible = False

    ' Allow the user to make the button visible.
    If DialogResult.Yes = MessageBox.Show( _
        "This sheet contains a hidden control." & _
        " Make it visible?", "Example", MessageBoxButtons.YesNo) Then
        ClickedButton.Visible = True
    End If
End Sub
private void AlterControlAppearance()
{
    Microsoft.Office.Tools.Excel.Controls.Button hideButton =
        this.Controls.AddButton(this.Range["B2", "C3"],
        "hideButton");

    hideButton.Text = "Click to hide";
    hideButton.Border.Color = ColorTranslator.ToOle(Color.Green);
    hideButton.Click += new EventHandler(hideButton_Click);
}

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

    // Allow the user to make the button visible.
    if (DialogResult.Yes ==
        MessageBox.Show("This sheet contains a hidden control." +
        " Make it visible?", "Example", MessageBoxButtons.YesNo))
    {
        clickedButton.Visible = true;
    }
}

.NET Framework 安全性

請參閱

參考

Button 類別

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