Advanced Form
Advanced Form
Modal forms
Let us create a typical windows main menu bar and sub menus using the old version controls
first since these controls are still much used in old applications.
Following is an example, which shows how we create a menu bar with menu items: File, Edit,
View and Project. The File menu has the sub menus New, Open and Save.
Let's double click on the Form and put the following code in the opened window.
https://www.tutorialspoint.com/vb.net/vb.net_advanced_forms.htm 1/11
1/1/23, 1:27 PM VB.Net - Advanced Form
mnuBar.MenuItems.Add(myMenuItemView)
mnuBar.MenuItems.Add(myMenuItemProject)
When the above code is executed and run using Start button available at the Microsoft Visual
Studio tool bar, it will show the following window −
Windows Forms contain a rich set of classes for creating your own custom menus with modern
appearance, look and feel. The MenuStrip, ToolStripMenuItem, ContextMenuStrip controls
are used to create menu bars and context menus efficiently.
https://www.tutorialspoint.com/vb.net/vb.net_advanced_forms.htm 2/11
1/1/23, 1:27 PM VB.Net - Advanced Form
1
MenuStrip
2
ToolStripMenuItem
3
ContextMenuStrip
https://www.tutorialspoint.com/vb.net/vb.net_advanced_forms.htm 3/11
1/1/23, 1:27 PM VB.Net - Advanced Form
1
Clear
2
ContainsData
Indicates whether there is data on the Clipboard that is in the specified format or can
be converted to that format.
3
ContainsImage
Indicates whether there is data on the Clipboard that is in the Bitmap format or can be
converted to that format.
4
ContainsText
Indicates whether there is data on the Clipboard in the Text or UnicodeText format,
depending on the operating system.
5
GetData
6
GetDataObject
7
GetImage
8
GetText
Retrieves text data from the Clipboard in the Text or UnicodeText format, depending
on the operating system.
9
GetText(TextDataFormat)
Retrieves text data from the Clipboard in the format indicated by the specified
TextDataFormat value.
https://www.tutorialspoint.com/vb.net/vb.net_advanced_forms.htm 4/11
1/1/23, 1:27 PM VB.Net - Advanced Form
10
SetData
Clears the Clipboard and then adds data in the specified format.
11
SetText(String)
Clears the Clipboard and then adds text data in the Text or UnicodeText format,
depending on the operating system.
Following is an example, which shows how we cut, copy and paste data using methods of the
Clipboard class. Take the following steps −
Add a rich text box control and three button controls on the form.
Change the text property of the buttons to Cut, Copy and Paste, respectively.
Double click on the buttons to add the following code in the code editor −
https://www.tutorialspoint.com/vb.net/vb.net_advanced_forms.htm 5/11
1/1/23, 1:27 PM VB.Net - Advanced Form
End Sub
End Class
When the above code is executed and run using Start button available at the Microsoft Visual
Studio tool bar, it will show the following window −
When you anchor a control to a form, the control maintains its distance from the edges of the
form and its anchored position, when the form is resized.
You can set the Anchor property values of a control from the Properties window −
https://www.tutorialspoint.com/vb.net/vb.net_advanced_forms.htm 6/11
1/1/23, 1:27 PM VB.Net - Advanced Form
For example, let us add a Button control on a form and set its anchor property to Bottom, Right.
Run this form to see the original position of the Button control with respect to the form.
Now, when you stretch the form, the distance between the Button and the bottom right corner of
the form remains same.
Docking of a control means docking it to one of the edges of its container. In docking, the control
fills certain area of the container completely.
The Dock property of the Control class does this. The Dock property gets or sets which control
borders are docked to its parent control and determines how a control is resized with its parent.
You can set the Dock property values of a control from the Properties window −
https://www.tutorialspoint.com/vb.net/vb.net_advanced_forms.htm 7/11
1/1/23, 1:27 PM VB.Net - Advanced Form
For example, let us add a Button control on a form and set its Dock property to Bottom. Run this
form to see the original position of the Button control with respect to the form.
Now, when you stretch the form, the Button resizes itself with the form.
Modal Forms
Modal Forms are those forms that need to be closed or hidden before you can continue working
with the rest of the application. All dialog boxes are modal forms. A MessageBox is also a modal
form.
https://www.tutorialspoint.com/vb.net/vb.net_advanced_forms.htm 8/11
1/1/23, 1:27 PM VB.Net - Advanced Form
Let us take up an example in which we will create a modal form, a dialog box. Take the following
steps −
Add a form, Form1 to your application, and add two labels and a button control to Form1
Change the text properties of the first label and the button to 'Welcome to Tutorials Point'
and 'Enter your Name', respectively. Keep the text properties of the second label as blank.
Add a new Windows Form, Form2, and add two buttons, one label, and a text box to Form2.
Change the text properties of the buttons to OK and Cancel, respectively. Change the text
properties of the label to 'Enter your name:'.
Set the FormBorderStyle property of Form2 to FixedDialog, for giving it a dialog box border.
Set the ControlBox property of Form2 to False.
When the above code is executed and run using Start button available at the Microsoft Visual
Studio tool bar, it will show the following window −
Clicking on the 'Enter your Name' button displays the second form −
https://www.tutorialspoint.com/vb.net/vb.net_advanced_forms.htm 10/11
1/1/23, 1:27 PM VB.Net - Advanced Form
Clicking on the OK button takes the control and information back from the modal form to the
previous form −
https://www.tutorialspoint.com/vb.net/vb.net_advanced_forms.htm 11/11