C# Simplified, part 7: Working with WinForm Controls - Working with Labels
(Page 4 of 6 )
A label is one of the important controls used with all kinds of applications, be they Windows or ASP.NET applications. They normally sit alongside the Textbox control, but labels will also find a place with other controls such as combo box and list box as well. It tells you what information to enter inside a specific control. The text inside the label controls cannot be edited. It cannot be modified by users. Listing 7.4 adds a Textbox and a label control to the form. Once you have worked with this example you can further modify the program by adding more controls.
Label 7.4
001: using System;
002: using System.Drawing;
003: using System.Windows.Forms;
004:
005: public class MyLabel: Form
006: {
007:
008: // Object of TextBox created
009: TextBox t1 = new TextBox();
010: // Object of Label created
011: Label l1 = new Label();
012:
013: MyLabel()
014: {
015: this.Controls.Add(l1);
016: this.Controls.Add(t1);
017: t1.Location = new Point(50,50);
018: t1.Size = new Size(200,70);
019: t1.Multiline = true;
020: t1.ScrollBars = ScrollBars.Vertical;
021: t1.CharacterCasing = CharacterCasing.Upper;
022:
023: l1.Text = "Enter your comments:";
024: l1.Location = new Point(50,30);
025: l1.Size = new Size(150,20);
026:
027: this.Text = "Label Control Demo";
028: }
029:
030: public static void Main()
031: {
032: Application.Run(new MyLabel());
033: }
034: }
Output

Figure 7.4
Next: Working with Combo boxes >>
More C# Articles
More By Anand Narayanaswamy