A label is a control that displays text to the user. The
user cannot directly change it but only allowed to read it. A label can be used
by itself or placed next to another control because such a control cannot
inherently indicated what it is used for.
To create a label, on the Toolbox, click the Label button
and click the form.
To programmatically create a label, declare a pointer to
Label. This would be done as follows:
public __gc class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
}
private:
Label *lblFirstName;
...
};
Use the new operator to initialize it using its default constructor.
Once you have created the control, you can change its
properties as you see fit. Here is an example: void InitializeComponent(void)
{
// First Name Label
this->lblFirstName = new Label;
this->lblFirstName->Text = S"&First Name";
this->lblFirstName->Location = System::Drawing::Point(20, 20);
. . .
this->Controls->Add(this->lblFirstName);
}
}
|