CBVP2103
MDI (Multiple Document Interface) forms are forms that are created to hold other forms. The MDI form is often referred to as the parent, and the forms displayed within the MDI parent are often called children.
In VB.NET, a regular form is converted to an MDI parent form by setting the IsMDIContainer property of the form to True. This is normally done in the Properties window at design time. A form can also be made into an MDI parent at runtime by setting the IsMDIContainer property to True in code. However, the design of an MDI form is usually rather different from that of a normal form, so this approach is not often needed.
In VB6, an MDI parent form can only contain controls that have a property called Align. This property determines to which side of the MDI parent form the control is supposed to be docked. Typical controls like buttons and text boxes cannot be added directly to an MDI parent form. They must be added to a container control, such as a PictureBox, which has an Align property. In VB.NET, an MDI parent can contain any control that a regular form can contain. Buttons, labels, and the like can be placed directly on the MDI surface. Such controls will appear in front of any MDI child forms that are displayed in the MDI client area.
In VB.NET, a form becomes an MDI child at runti ntime me by setting the form’s MDIParent property to point to an MDI parent form. In fact, the MDIParent property cannot t be set at design time. (Note that this is completely different from VB6, where it was necessary to make a form an MDI child at design time.) Any number of MDI child forms can be displayed in the MDI parent client area. The currently active child form can be determined with the ActiveForm property of the MDI parent form.
There are three basic techniques for the creation of custom Windows Forms controls in .NET: ◦ Inherit from an existing control ◦ Build a composite control (using the UserControl class as your starting point) ◦ Write a control from scratch (using the very simple Control class as your starting point)
The simplest technique starts with a complete Windows Forms control that is already developed. A new class is created that inherits the existing control. Most of the built-in Windows Forms controls can be used as the base class for such an inherited control.
Here are some typical examples where it might make sense to extend an existing Windows Forms control: ◦ A text box with built-in validation for specific types of information ◦ A self-loading list box, combo box, or data grid ◦ A menu control that varies its options based on the current user ◦ A NumericUpDown control that generates a special event when it reaches 80 percent of its maximum allowed value
In some cases, a single existing control does not furnish the needed functionality, but a combination of two or more existing controls does. Here are some typical examples: ◦ A set of buttons with related logic that are always used together (such as “Save,” “Delete,” and “Cancel” buttons on a file maintenance form) ◦ A set of text boxes to hold a name, address, and phone number, with the combined information formatted and validated in a particular way ◦ A set of option buttons with a single property exposed as the chosen option ◦ A data grid together with buttons that alter its appearance or behavior in specific ways
If a control needs to have special functionality not related to any existing control, then it can be written from scratch to draw its own visual interface and implement its own logic. This option requires more work, but allows us to do just about anything that is possible within .NET and Windows Forms, including very sophisticated drawing of a user interface. To write a control from scratch, it is necessary to inherit from the Control class, which gives basic functionality such as properties for colors and size.
Recommend
More recommend