A text box is a control that is used to display text
to, or receive text from, the user. It is presented as a rectangular box
that cannot indicate what it is used for. For this reason, a text box is
usually accompanied by a label that indicates its purpose.
To create a text box, on the Toolbox, click the TextBox
button and click the form.
The TextBox control is based on the TextBox
class. This can be used to programmatically create the control. To do
this, declare a pointer to TextBox. Use the new operator to
initialize it with its default constructor.
- Start Microsoft Visual Studio .NET
- On the Start Page, click New Project (alternatively, on the main
menu, you can click File -> New -> Project...)
- On the New Project dialog box, in the Project Types tree list, click
Visual C++ Projects
- In the Templates list, click Managed C++ Empty Project
- In the Name edit box, replace the <Enter name> content with Text
Box Example
- In the Location combo box, accept the suggestion or type your own.
If you don't have any, type C:\Programs\MSVC.NET
- Click OK
- On the main menu, click Project -> Add New Item...
- In the Add New Item dialog box, in the Templates list, click C++
File
- In the Name box, replace <Enter name> with Main
and click OK
- Replace the contents of the empty file with the following (I have
commented the whole file to indicate what each piece of code does):
#using <mscorlib.dll>
#using <System.dll>
#using <System.Drawing.dll>
#using <System.Windows.Forms.dll>
using namespace System;
using namespace System::Drawing;
using namespace System::Windows::Forms;
__gc class SimpleForm : public Form
{
public:
SimpleForm();
private:
TextBox *txtBox;
};
SimpleForm::SimpleForm()
{
txtBox = new TextBox;
txtBox->Location = Point(100, 16);
Controls->Add(txtBox);
}
int __stdcall WinMain()
{
SimpleForm * FM = new SimpleForm();
Application::Run(FM);
return 0;
}
|
- Press Ctrl + F5 to test the application
|
|