A Managed C Windows Forms Application

A Managed C++ Windows Forms Application

Applications developed in managed C++ have access to all of the classes that come with the .NET Framework. However, the first release of Visual C++ .NET, now referred to as Visual C++ .NET 2002, did not provide any Rapid Application Development (RAD) support for building Windows Forms applications in managed C++. Developers had to code these applications manually. With the release of Visual C++ .NET 2003 comes wizard and designer support for forms applications.

Whether created with a designer or manually, managed C++ Windows Forms applications run only on machines with the .NET Framework installed. They can use libraries written in any .NET supported language, and thanks to "It Just Works" technology, they can also use unmanaged C++ libraries.

To create a Windows Forms application, choose File, New Project or click New Project on the Start Page. Select Visual C++ projects on the left, and Windows Forms application (.NET) on the right. Name the project SimpleForm , as shown in Figure 4.1.

Figure 4.1. Visual Studio can create a Windows Forms application in managed C++.

graphics/04fig01.gif

The project wizard creates a blank form for you, and later you'll drag controls onto it. It also generates a file full of code, which will be edited as you add controls and set properties. To see the code, right-click the form in the designer and choose View Code.

When the application runs, the runtime creates an instance of the form class, which is why it must be a garbage-collected class:

 
 public __gc class Form1 : public System:: Windows::Forms::Form { // . . . }; 

The runtime then calls the InitializeComponent() method of the class. When the form is first created, InitializeComponent() looks like this:

 
 void InitializeComponent(void) {    this->components = new System::ComponentModel::Container();    this->Size = System::Drawing::Size(300,300);    this->Text = S"Form1"; } 

Switch back to the designer (use the tabs across the top of the editor, or press Ctrl+Tab) and bring up the properties of the form by choosing View, Properties Window. Use the Properties window to change some aspects of the form such as the Text property, the background color , and the like. Use your mouse to resize the form. Without saving your work, switch back to the code view and you will see that the designer has updated the code to reflect your changes. Switch back to the code and edit it (for example, change the size), and then switch to Design view again and you'll see your code changes take effect in the designer.

Although it can be fun to play with your code in this way, for day-to-day work you'll generally ignore this code. Let the designer maintain it, and use the toolbox and the Properties window to work with your form.



Microsoft Visual C++. NET 2003 Kick Start
Microsoft Visual C++ .NET 2003 Kick Start
ISBN: 0672326000
EAN: 2147483647
Year: 2002
Pages: 141
Authors: Kate Gregory

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net