Rogue Wave banner
Previous fileTop of DocumentContentsIndex pageNext file
Objective Grid for Microsoft .NET User's Guide
Rogue Wave web site:  Home Page  |  Main Documentation Page

8.3 1stGrid - Step 2

In Step 2, you will change the Step 1 application in several ways:

This section requires the most work of any of the steps in this tutorial.

8.3.1 Create a New Project

First, add a new project to the 1stGrid solution for the Step 2 application.

  1. In the Solution Explorer, right click on the 1stGrid solution.

  2. In the resulting context menu, select the Add | New Project option.

  3. Right-click Step 2.

  4. Resize the form as desired.

  5. In the property grid for the form, change the following properties:

8.3.2 Add a Menu

  1. If the Toolbox is not already visible, then make it visible using the View | Toolbox menu option.

  2. Drag a main menu from the Toolbox onto the form.

  3. Click mainMenu1 at the base of the form designer.

  4. You will now add all of the menu options for the application.

  5. Now, for each menu item, do the following. First, select the item. In the property grid, rename the item, giving it a more meaningful name. Then give it a shortcut (if desired). Suggested names and shortcuts follow.

    Table 35: Suggested Menu Item Names and Shortcuts

    FileMenu
    FileNew (CtrlN)
    FileClose
    FileExit
    EditMenu
    EditUndo (CtrlZ)
    EditRedo (CtrlR)
    EditCopy (CtrlC)
    EditCut (CtrlX)
    EditPaste (CtrlV)
    EditClear
    EditFind (CtrlF)
    EditReplace (CtrlH)
    WindowMenu
    WindowCascade
    WindowTileHorizontal
    WindowTileVertical
    HelpMenu
    HelpAbout

    Figure 37: Menu Command Design

8.3.3 Add the GridDocument Class

The next steps add a GridDocument class to the application. A GridDocument is a document class that represents a document. Each GridDocument contains a grid that can be manipulated by the user.

  1. From the Solution Explorer, right click Step2 (context menu).

  2. Select Add | Add Windows Form.

  3. Size the form as desired.

  4. Select the GridDocument form.

  5. Make the following changes to the form's properties.

  6. Select and drag a GridControl from the Toolbox onto the form.

  7. Size and position the grid in the form, as desired.

  8. Select the grid control. In the property grid for the control, set the properties shown in Table 36

    Table 36: GridControl Properties

    Property Value
    DrawGrid false
    BorderStyle Sunken
    Anchor Top, Bottom, Left, Right
    AutoScroll true
    ColCount 15
    RowCount 40


    DrawGrid is a property of the form; it is not a Rogue Wave property.

  9. From the View menu, select Code to edit the source code for the form.

  10. Modify the GridDocument constructor to accept one argument, a string containing the document name. Also, after the comment, "TODO: Add any constructor code after InitializeComponent call", add the line:

      this.Text = docName;
      

    The code now looks like this:

      public GridDocument(string docName)
      {
         //
         // Required for Windows Form Designer support
         //
         InitializeComponent();
      
         //
         // TODO: Add any constructor code after InitializeComponent call
         //
         this.Text = docName;
      }
      
  11. Switch to Class View. If the class view is not visible, you can access it using the View | Class View menu option.

  12. Expand the class view tree as follows: Step 2 | NameSpaces | Step_2 |GridDocument.

  13. With the GridDocument class visible, right click the GridDocument class.

  14. Close the source code window and the design view for GridDocument.

8.3.4 Add an "About" Box

  1. Return to the Solution Explorer.

  2. Right click on Step 2.

  3. From the context menu that appears, select Add | Add Windows Form.

  4. Size the form as desired.

  5. Select the form. Make the following changes to the form properties:

  6. Drag a group box from the Toolbox onto the form.

  7. Select the group box.

  8. Change the Text property for the group box to "" (no text).

  9. Size the group box to form a border around the perimeter of the window.

    Figure 38: About Dialog Box

  10. Drag a label from the Toolbox onto the form.

  11. Select the label, and change its properties as follows:

  12. Size the label as needed, in order to properly display the text.

  13. With the label selected, center the label in the form with the Format | Center in Form | Horizontally menu option from the Visual Studio main menu.

  14. Drag a button from the Toolbox onto the form.

  15. With the button selected, center the Button in the form with the Format | Center in Form | Horizontally menu option.

  16. Ensure the button is still selected. Change its properties as follows:

  17. Click the events button in the property grid (the lightning bolt).

  18. Double-click the Click event.

  19. Add this code for the button's click event:

  20. Close the source code editor.

  21. Close the design view for HelpAbout.

8.3.5 Add MDI Support

You will now update the source code for Form1 to add support for the MDI interface.

  1. View the source code for Step 2 Form1.cs.

  2. Add a new private int property, the document counter:

  3. Add the following code after the "TODO: Add any constructor code after InitializeComponent call" comment:

  4. Add the following implementation for the AddDocument method:

8.3.6 Add Event Handlers

Finally, you will add event handlers for all of the menu options in the application menu.

  1. Go to the design view for Form1.cs.

  2. First, you will implement the File | New event handler.

  3. Next, implement the File | Close event handler.

  4. The following source code shows the implementations for the remaining menu item click event handlers.

  5. Build and run the application.

Congratulations! You've completed the longest portion of the 1stGrid tutorial.

Figure 39: Completed 1stGrid Step 2



Previous fileTop of DocumentContentsNo linkNext file

Copyright © Rogue Wave Software, Inc. All Rights Reserved.

The Rogue Wave name and logo, and Stingray, are registered trademarks of Rogue Wave Software. All other trademarks are the property of their respective owners.
Provide feedback to Rogue Wave about its documentation.