CPS613

VB .NET Techniques and References

Toronto Metropolitan University University

Windows and Forms


Table of Contents

Special Windowing and Pop-Ups

Whole Window Controls


Special Windowing and Pop-Ups

MDI: Multiple Document Interface

Some windows application, such as Paint and Photoshop, employ a user interface model called MDI (Multiple Document Interface) which lets users work on multiple documents of the same type at the same time. In this type of interface, the main window is called the "Parent" window and the windows which contain the documents which are being worked one simultaneously are called the "Children" windows. Typically the parent window contains a menu and toolbars which are used to act on one of the opened document, the "active" document.

In .NET, MDI is implemented using one MDI form, called the parent form, inside of which other forms (called children forms) exist. When designing an MDI application, the main form is typically the MDI Parent form and the documents being worked on are children form. As usual, only the class of the child form is defined in .NET and this class is instantiated whenever a new document is opened.

Many of the generic MDI features such as the standard menu are built-in the MDI items in Visual Studio. To use these:

Then you can customize the menu and toolbar to your assignment and edit the event drivers for that form. Here is the MSDN documentation on MDI. Once you have created the parent form you can create one child form which will be a template for all the children and instantiated whenever a new file is opened.

Dialog boxes

Dialog boxes are pop-up windows which display information to the user and then await a simple command to close the window. They have multiple uses in windowing user interfaces: usually to collect information from the user or to explain something to the user as in help windows.

.NET and Visual Studio have some built-in classes and form templates to facilitate the creation of dialog boxes: These forms can be created with the Add New Item option by selecting "Dialog" (for a generic dialog box).

.NET also provides some standard windows dialog-box controls and components that you can use in your applications to select colors and fonts, to open and save files, and to set up a page, preview it, and print it.

Once created, dialog boxes are invoked using the ShowDialog Method which will return a different status depending on which button users press to complete their work with the dialog box. This allows the programmer to handle "OK" and "Cancel" (or other actions) differently.

About boxes

In .NET an about box is simply a type of form. You can add such a box via the Add New Item option .

Text Windows

You can make a dialog box (or any other form) display formatted text from an external file by
  1. saving the file in Text format (.txt) or Rich Text Format (.rtf).
  2. adding a RichTextBox Control to the form
  3. loading the text or rtf file into the rtf control
RichTextBox controls are editable, just like TextBoxes. The contents of RichTextBox controls can be saved in files.

Context-Sensitive Menus

Context-sensitive menus (menus invoked by a right click) can either be associated with a window or with an object in the window. In both cases, they are implemented with a ContextMenuStrip Control which is added to the Form representing the window or to the control representing the object. In the second case, one usually makes the control a user-defined control because the same type of context-sensitive menu applies to all objects of the same type.

In Visual Studio, menu options are added to the context sensitive menu through the Items property. For cascading menus, the sub-menu of a menu option is added through the DropDownItems property of the first menu.


Whole Window Controls

Menus

Menus are implemented using a MenuStrip Control This control is fairly intuitive. You can drag the control into your form and start editing it directly. (If you are using an MDI form, you do not need to do this because the MDIform will create a default menu that you can use.)

Editing this menu is fairly intuitive. Separators are defined by typing a dash (-) into one of the entries.

Toolbars

You can create toolbars in VB with the Toolstrip control

You can create your own bitmaps for the icons in the toolbars/strips directly in VB by Add New Item | Icon File. The icons created will be of the right size and they will also have a transparent background.

The standard Microsoft icons that you can use in your toolbars are in the \Common7\VS2008ImageLibrary\1033\VS2008ImageLibrary.zip file of your Visual Studio installation directory (which can be either "C:\Program Files\Microsoft Visual Studio 9.0" or "C:\Program Files (x86)\Microsoft Visual Studio 9.0"). As you will notice, each picture is available in multiple sizes. You can use Microsoft Paint to edit these pictures to pick the size that fits your buttons best (which you can determine from the Size property of your control) and then add these as Resources which you can them simply select as your button pictures.

Status Bar

The status bar is implemented with a StatusStrip control. Just like the menustrip control you can add elements directly into the status stip at design time.

In particular, the ToolStripProgress Bar can be added with the designer by clicking directly into the status strip. You do not need to drag a separate ProgressBar control from the toolbox. These other ProgressBar controls are intended to be integrated in different areas of the window.

The Spring Property of an element of a StatusStrip is used to specify whether that element will expand to fill the entire status bar if it can. By default, it is set to False, which means that by default the elements of a status strip will remain on the left of the Status strip. If you want to have some of these elements on the right instead, you should set their Spring property to True.


This page is maintained by Sophie Quigley (cps613@cs.torontomu.ca)
Last modified Thursday, 20-Oct-2022 11:53:47 EDT