Leer en inglés

Compartir a través de


Button.Visible Property

Definition

Gets or sets a value that represents whether the Button is visible.

C#
public bool Visible { get; set; }

Property Value

true if the Button is visible; otherwise, false.

Examples

The following code example adds a Button control to a worksheet and uses the Border property to color the border of the cell green. The Click event handler of the button uses the Visible property to hide the button, and then prompts the user to choose to either unhide the button, or allow it to remain hidden.

This example is for a document-level customization.

C#
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;
    }
}

Applies to

Producto Versiones
Visual Studio Tools for Office 2017, 2019, 2022