A. Two ways of creating lables in .NET
1. Create label in design time
To create a Label control at design-time, you simply drag and drop a Label control from Toolbox to a Form. After you drag and drop a Label on a Form. After then you can move it around and resize it using mouse and set its properties and events.
2. Create label in run time
As we have said before, the Label class is defined in the System.Windows.Forms namespace and it represents a Label control.The following code snippet creates a Label control object.
// Create a Label object
Label myLabel = new Label();
B. Setting Label Properties
The easiest way to set properties is from the Properties Window. open Properties window by pressing F4 or right click on a control and select Properties menu item. The Properties window looks like:
Of course, We can set its properties by code in run time:
Example:
//set its name
myLabel.Name = "DynamicLabel";
//set label text
myLabel.Text = "I am Dynamic Label";
myLabel.TextAlign = HorizontalAlignment.Center;
int size = myLabel.TextLength;
myLabel.TextAlign = HorizontalAlignment.Center;
int size = myLabel.TextLength;
No comments:
Post a Comment