In Windows Forms, Label control is used to display text on the form and it does not take part in user input or in mouse or keyboard events. You are allowed to set the visibility of the Label control using the Visible Property in the windows form. The label is visible when the value of this property is set to be true.
If the value of this property is set to be false, then the Label does not visible in the form. The default value of this property is true. You can set this property using two different methods:
1. Design-Time: It is the easiest method to set the Visible property of the Label control using the following steps:
- Step 1: Create a windows form as shown in the below image:
Visual Studio -> File -> New -> Project -> WindowsFormApp

- Step 2: Drag the Label control from the ToolBox and drop it on the windows form. You are allowed to place a Label control anywhere on the windows form according to your need.

- Step 3: After drag and drop you will go to the properties of the Label control to set the Visible property of the Label.
Output:

2. Run-Time: It is a little bit trickier than the above method. In this method, you can set the visibility of the Label control in the windows forms programmatically with the help of given syntax:
public bool Visible { get; set; }
Here, the value of this property is of System.Boolean type. Following steps are used to set the Visible property of the Label:
- Step 1: Create a label using the Label() constructor is provided by the Label class.
// Creating label using Label class Label mylab = new Label();
- Step 2: After creating Label, set the Visible property of the Label provided by the Label class.
// Set Visible property of the label mylab.Visible = true;
- Step 3: And last add this Label control to form using Add() method.
// Add this label to the form this.Controls.Add(mylab);
Example:
usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;usingSystem.Windows.Forms;namespaceWindowsFormsApp16 {publicpartialclassForm1 : Form {publicForm1(){InitializeComponent();}privatevoidForm1_Load(objectsender, EventArgs e){// Creating and setting the labelLabel mylab =newLabel();mylab.Text ="GeeksforGeeks";mylab.Location =newPoint(222, 90);mylab.AutoSize =true;mylab.Font =newFont("Calibri", 18);mylab.ForeColor = Color.Green;mylab.Visible =true;// Adding this control to the formthis.Controls.Add(mylab);// Creating and setting the labelLabel mylab1 =newLabel();mylab1.Text ="Welcome To GeeksforGeeks";mylab1.Location =newPoint(155, 170);mylab1.AutoSize =true;mylab1.Font =newFont("Calibri", 18);mylab1.Visible =false;// Adding this control to the formthis.Controls.Add(mylab1);}}}chevron_rightfilter_noneOutput:
When the value of Visible Property is set to be true:

When the value of Visible Property is set to be false:

Recommended Posts:
- How to set the Visibility of the Button in C#?
- How to set the Visibility of the RadioButton in C#?
- How to set the Visibility of the TextBox in C#?
- How to set the visibility of the CheckBox in C#?
- How to set the Visibility of the ComboBox in C#?
- How to set the Visibility of ListBox in C#?
- How to set the Visibility of MaskedTextBox in C#?
- How to set the Visibility of the NumericUpDown in C#?
- How to Set the Visibility of the GroupBox in C#?
- How to set the Visibility of DateTimePicker in C#?
- How to set the Visibility of the FlowLayoutPanel in C#?
- C# | How to change the visibility of the Cursor of Console
- How to set the Size of the Label in C#?
- How to set the Foreground Color of the Label in C#?
- How to set the Background Color of the Label in C#?
- How to set the Font of the Content Present in the Label in C#?
- How to set Text on the Label in C#?
- How to Set the Location of the Label in C#?
- How to Set the Padding of the Label in C#?
- How to set the Alignment of the Text in the Label in C#?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

