Creating MDI Parent Forms
The foundation of a Multiple-Document Interface (MDI) Application is the MDI parent form. This is the form that contains the MDI child windows, which are the "sub-windows" wherein the user interacts with the MDI application. Creating an MDI parent form is easy, both in the Windows Forms Designer and programmatically.
To create an MDI parent form at design time
1. Create a Windows Application. For more information, see Creating a Windows Application Project.
2. In the Properties window, set the IsMDIContainer property to true.
This designates the form as an MDI container for child windows.
Note While setting properties in the Properties window, you can also set the WindowState property to Maximized, if you like, as it is easiest to manipulate MDI child windows when the parent form is maximized. Additionally, be aware that the edge of the MDI parent form will pick up the system color (set in the Windows System control panel), rather than the back color you set using the Control.BackColor property.
3.From the Toolbox, drag a MainMenu component to the form. Create a top-level menu item with the Text property set to &File with submenu items called &New and &Close. Also create a top-level menu item called &Window.
The first menu will create, and hide menu items at run time, and the second menu will keep track of the open MDI child windows. At this point, you have created an MDI parent window. For more information on creating menus and menu items, see Adding Menus and Menu Items to Windows Forms.
4. Press F5 to run the application. For information about creating MDI child windows that operate within the MDI parent form, see Creating MDI Child Forms.
DATA Types
A dat type of a variable or constant indicates what type of information will be stored in the allocated memory space: perhaps a name, a dollar amount, a date, or a total.
Note that the default data type is variant. If you do not specify a data type, your varibles and constants will be variants.
Data Types
Boolean - True or false values
Byte - A single ASCII character (code 0 to 255)
Currency - Decimal fractions, such as dollars and cents.
Date - An eight-character date.
Double - Double precision floating point numbers with 14 digits of accuracy.
Integer - Whole numbers in the range -32,768 to 32,767
Long - Larger whole numbers
Single - Single precision floating point numbers with six digits of accuracy.
String - Alphanumeric data: letters, digits, and other characters.
Variant - Converts from one type to another, as needed.
Modules in VB
A VB project is a collection of the following modules and files.
The global module( that contains declaration and procedures)
The form module(that contains the graphic elements of the VB application along with the instruction )
The general module (that generally contains general-purpose instructions not pertaining to anything graphic on-screen)
The class module(that contains the defining characteristics of a class, including its properties and methods)
The resource files(that allows you to collect all of the texts and bitmaps for an application in one place)
The Standard Code Module
If you will need the procedure in multiple forms, write the procedure in a Standard Code Module.
A SCM is a Basic file with the extension .bas, which is added to the project. SCM does not contain any form, only code.
Controls
A control is an object that can be drawn on to the Form to enable or enhance user interaction with the application. Examples of these controls, TextBoxes, Buttons, Labels, Radio Buttons, etc. All these Windows Controls are based on the Control class, the base class for all controls. Visual Basic allows us to work with controls in two ways: at design time and at runtime. Working with controls at design time means, controls are visible to us and we can work with them by dragging and dropping them from the Toolbox and setting their properties in the properties window. Working at runtime means, controls are not visible while designing, are created and assigned properties in code and are visible only when the application is executed. There are many new controls added in Visual Basic .NET and we will be working with some of the most popular controls in this section. You can select the controls from the menu towards the left-hand side of this page.
Notable properties of most of these Windows Controls which are based on the Control class itself are summarized in the table below. You can always find the properties of the control with which you are working by pressing F4 on the keyboard or by selecting View->Properties Window from the main menu.
ComboBox
ComboBox is a combination of a TextBox and a ListBox. The ComboBox displays an editing field (TextBox) combined with a ListBox allowing us to select from the list or to enter new text. ComboBox displays data in a drop-down style format. The ComboBox class is derived from the ListBox class. Below is the Image of a ComboBox.
Notable properties of the ComboBox
The DropDownStyle property in the Appearance section of the properties window allows us to set the look of the ComboBox. The default value is set to DropDown which means that the ComboBox displays the Text set by it's Text property in the Textbox and displays it's items in the DropDownListBox below. Setting it to simple makes the ComboBox to be displayed with a TextBox and the list box which doesn't drop down. Setting it to DropDownList makes the ComboBox to make selection only from the drop down list and restricts you from entering any text in the textbox.
We can sort the ComboBox with it's Sorted property which is set to False by Default.
We can add items to the ComboBox with it's Items property.
ComboBox Event
The default event of ComboBox is SelectedIndexChanged which looks like this in code:
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object,_
ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
End Sub
Working with ComboBoxes
Drag a ComboBox and a TextBox control onto the form. To display the selection made in the ComboBox in the Textbox the code looks like this:
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object,_
ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
TextBox1.Text = ComboBox1.SelectedItem
'selecting the item from the ComboBox with selected item property
End Sub
Removing items from a ComboBox
You can remove all items or one particular item from the list box part of the ComboxBox. Code to remove a particular item by it's Index number looks like this:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As_
System.EventArgs) Handles Button1.Click
ComboBox1.Items.RemoveAt(4)
'removing an item by specifying it's index
End Sub
Code to remove all items from the ComboBox
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As_
System.EventArgs) Handles Button1.Click
ComboBox1.Items.Clear()
'using the clear method to clear the list box
End Sub
RadioButton
RadioButtons are similar to CheckBoxes but RadioButtons are displayed as rounded instead of boxed as with a checkbox. Like CheckBoxes, RadioButtons are used to select and deselect options but they allow us to choose from mutually exclusive options. The RadioButton control is based on the ButtonBase class which is based on the Control class. A major difference between CheckBoxes and RadioButtons is, RadioButtons are mostly used together in a group. Below is the image of a RadioButton.
Important properties of the RadioButton in the Appearance section of the properties window are:
Appearance: Default value is Normal. Set the value to Button if you want the RadioButton to be displayed as a Button.
BackgroundImage: Used to set a background image for the RadioButton.
CheckAlign: Used to set the alignment for the RadioButton from a predefined list.
Checked: Default value is False, set it to True if you want the RadioButton to be displayed as checked.
FlatStyle: Default value is Standard. Select the value from a predefined list to set the style of the RadioButton.
RadioButton Event
The default event of the RadioButton is the CheckedChange event which looks like this in code:
Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object,_
ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged
End Sub
Working with Examples
Drag a RadioButton (RadioButton1), TextBox (TextBox1) and a Button (Button1) from the Toolbox.
Code to display some text when the RadioButton is selected
Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged
TextBox1.Text = "RadioButton Selected"
End Sub
Code to check a RadioButton's state
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As_
System.EventArgs) Handles Button1.Click
If RadioButton1.Checked = True Then
TextBox1.Text = "Selected"
Else
TextBox1.Text = "Not Selected"
End If
End Sub
Creating a RadioButton in Code
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As_
System.EventArgs) Handles_ MyBase.Load
Dim RadioButton1 As New RadioButton()
RadioButton1.Text = "RadioButton1"
RadioButton1.Location = New Point(120,60)
RadioButton1.Size = New Size(100, 50)
Me.Controls.Add(RadioButton1)
End Sub