What is a (MDI) Form object in visual basic?
A windows form is the basic visual element and place holder for other controls in any windows application. Without Forms we can not provide GUI (Graphical User Interface) in any applications. In VB projects there are two types of Forms. An MDI (Multiple documents Interface) and simple form.MDI Forms are container / parent form for all other child forms in an Application. Normally a windows application needs several child forms for various functions. These forms will open inside an MDI parent window. A good example for MDI application is Microsoft office word, in which all word documents are opened inside the parent window. We can use Tile Horizontally, Tile Vertically, Cascade functions to arrange the child forms inside the MDI parent form.
In order to create an MDI application you have to add atleast one MDI form to your application. The select the child form, in the properties window, set 'MDI child' property 'true'. Otherwise you will get error 'No MDI form available to load'.
To add a form open project explorer, by pressing ctrl+R or View -> Project Explorer menu. Then right click Forms Folder, click Add, Click form, Mdi form etc.
Now we will see some important properties, events and methods supported by the form object.
BackColor: Set the background colour of the form.
Caption: This is used to set the Window's Title bar text.
BorderStyele: Set the appearance of the border. 0-None: No border, 1-Fixed Single, 2-Sizable,3-FixedDialog, 4-FixedToolWindow,5-SizableToolWindow
ClipControls: Determines whether graphics methods in paint events repaint an entire object or newly.
ControlBox: Returns a value indicationg whether a Control-Menu box is displayed on a form at run time. (True/False)
Font: Set the font name size, Bold Italic etc.
Height: Height of the form
KeyPreview: Returns/sets whether keyboard events for an object are invoked before keyboard events for controls on that object.
Left: Returns/sets the distance between the internal edge of an object and the left edge of its container. Typically the left determines the distance from the screen's left edge to the form's left edge in twips unit.
MaxButton: Set to true if you want to display the Maximize button otherwise set to false.
MDIChild: Set to true if the form is an mdi child displayed inside an Mdi parent window.
MinButton: Set to true to display the minimize button
StartupPosition: Returns or sets a value specifying the position of a form when it first appears. The constants are 0-manual, 1-centerowner, 2-centerscreen, 3-Windows default.
Width: Width of the form in twips
Windowstate: Returns/sets the visual state of a frm window at run time. 0-normal, 1-minimized, 2-maximized.
The important events of the form are Initialize, Load, Activate, Unload, Terminate. While opening the form Initialize event will occur first. In this portion you will write the code to initialize form variables set properties etc. Then load event will occur. Activate event occur next. Activate will occur every time the form becomes an active form. That mean if you minimized the form for some time and maximize it again the activate event will occur. Initialize and load will occur only once. While closing the form Unload will fire first then Terminate event. Write your clean up code in unload. Destroy/free any global variables here.
Method / functions supported by VB Forms
Visual basic forms support the following methods. The most common are show, hide, and refresh. We will use show() method to display a form. This will load a form and display it on the screen. Hide will hide the form. Refresh will repaint the form and updates display. PrintForm method is used to print the form using printer.
So we have learned the basics of Windows Forms creation in VB. Just open a standard exe project and play with these properties, methods and events to familiarize with them. We will move on to the next level.