Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint

12.5. Using Windows Forms

A Windows form is an entity that represents a window of some kind. By a window I mean window in its most general sense, being an area on the screen that can be a button a dialog, a regular window, or any other kind of visible GUI component. A Windows form is encapsulated by the a subclass of the System::Windows::Forms::Form class, but you don't need to worry about this much initially, because all the code to create a form is created automatically. To see just how easy it's going to be, create a basic window using Windows Forms that has a standard menu.

A Windows Forms Application

Choose the CLR project type in the New Project dialog and select the Windows Forms Application as the template for the project. The New Project dialog window is shown in Figure 12-7.

Enter the project name as Ex12_03. When you click the OK button the Application Wizard generates the code for the Windows form application and displays the design window containing the form as it is displayed by the application. This is shown in Figure 12-8.

Figure 12.7. Figure 12-7


Figure 12.8. Figure 12-8


You can now make changes to the form in the design pane graphically, and the changes are automatically reflected in the code that creates the form. For a start, you can drag the bottom corner of the form with the mouse cursor to increase the size of the form window. You can also change the text in the title bar—right-click in the client area of the form and select Properties from the context menu. This displays the Properties window that allows you to change the properties for the form. From the list of properties to the right of the design pane, select Text, and then enter the new title bar text in the adjacent column showing the property value—I entered A Simple Form Window. When you press the key, the new text appears in the title bar of the form.

Just to see how easy it really is to add to the form window, display the Toolbox pane by selecting the tab on the right of the window if it is present, or by pressing Ctrl+Alt+X or by selecting Toolbox from the View menu. Find the MenuStrip option in the Menus and Toolbars list and drag it on to the form window in the Design tab pane. Right-click the MenuStrip1 that appears below the form window and select Insert Standard Items from the pop-up. You'll then have the menu in the form window populated with the standard File, Edit, Tools, Help menus, each complete with its drop-down list of menu items. The result of this operation is shown in Figure 12-9.

Figure 12.9. Figure 12-9




  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial