Label myLabel = new Label(); myLabel.Text = "Hello World!"; myLabel.Location = new System.Drawing.Point(50, 50); myLabel.AutoSize = true; this.Controls.Add(myLabel);
Label myLabel = new Label(); myLabel.Font = new Font("Arial", 12, FontStyle.Bold | FontStyle.Italic); myLabel.Text = "This is styled text."; this.Controls.Add(myLabel);This code creates a Label object with a customized font (Arial, 12pt, bold and italic), sets the text to "This is styled text.", and adds it to the form. The Label class is part of the System.Windows.Forms library, which provides a variety of GUI controls for Windows applications in C#.