Monday, November 8, 2010

Overview of Label

Creating A Label:
 
1] Labels are used to identify form content; They are used for prompts and to provide extraneous information on forms.  To create a label on the form, drag a Label from the Toolbox to the Faculty form. We are about to create a Label for a prompt -> First Name. (See Below!)

 
Moving A Label About The Form:
 
1] The label is an object created on the form with the line of code:
    this.label1 = new System.Windows.Forms.Label();
2] When you select the form with the mouse, you can see a box that identifies object label1. A dark background can make this box more difficult to identify. (See Below!)

     
 
3] Note the appearance of the cross-hairs icon when the mouse is moved over object label1 below. 


4] If you right mouse click on the label, you can drag it to the desired location on the form. Note the box that is formed around the label as you move it.


 
 
Changing The Label's Font:
 
1] Go to the properties panel for the label (right mouse clicking on the label. --> Select Properties)       (See Below!)

2] Select the Font Property. You can see that the current font is 12pt Ariel bold.  Suppose we wish to change the font to Comic Sans MS.  Hold down the font selector    (See Below!)

3] Select the Comic Sans MS font - Regular style - 16 point. Using the mouse,  select/push the OK button. (See Below!) 
4] Note the font change below.
5] You may select select and change multiple labels, using the procedure outlined above, at one time.
6] When doing multiple labels, it is often more efficient to set the Font associated with the form; thus it becomes the default.
 
Changing The Label's Color:
 
1] Return to the properties panel for the label (right mouse clicking on the label. --> Select Properties).  Select the ForeColor Property. You can see that the current forecolor is white.  Suppose we wish to change the forecolor to yellow.  Press the color selector drop-down control    (See Below!)
and select Yellow from the Custom Color Pallet. (See Below!) 
2]  Note that the label color has been changed below!
 
 
Changing The Label's Background Color:
1] Return to the properties panel for the label (right mouse clicking on the label. --> Select Properties).  Select the BackColor Property. You can see that the current backcolor is navy.  Suppose we wish to change the forecolor to purple.  Press the color selector drop-down control     (See Below!)


and select a purple from the Custom Color Pallet. (See Below!) 


2]  Note that the label color has been changed below!

   


Changing The Label's Text:
 
1] Return to the properties panel for the label (right mouse clicking on the label. --> Select Properties).  Select the Text Property. You can see that the current text is label1.  Suppose we wish to change the text to First Name. Change the Text Property to First Name. (See Below!)


2]  Replace button1 with First Name. The label is now a prompt for the First Name. (See Below!) 


4] This form still executes; try it. Note that the label object is no longer outlined. (See Below!)

Close the Faculty form

 
Naming A Label:
 
1] Some developers name each and every object on a form; I name almost every object, except labels. If you wish to change one or more of the label properties with program code, it should be named; otherwise I encourage you to consider it optional.
2] The name should contain no blanks. Suppose we wish to name the label - labFirstName.
3] Return to the properties panel for the label (right mouse clicking on the label. --> Select Properties).  Select the Name Property. You can see that the current name is label1. Change the Name Property to labFirstName. (See Below!)


2]  You can see that the label below has now been named.

 

No comments:

Post a Comment