Table of Contents
hide
Forms (Windows)
- Windows Forms and examples in Visual Basic .Net are the basic objects used to develop an application.
- It also contains the coding as well as the controls embedded in it to create the user interface.
- Forms are created by default when a Project is created in VB .Net with a default name Form1.
- Every form has its Properties, Methods, and Events.
- The common form properties are name, text, caption, color, etc., and are changed as required.
- There are multiple forms associated with a typical Project.
SDI & MDI
- Single Document Interface (SDI):
- SDI is an application software Interface/GUI tool that opens a single document each time in its primary window after prompting to close the previously opened one.
- SDI contains/controls one window only at a time. Thus, SDI supports only one interface /application at a time, and hence, slow processing.
- Here, each window has its menu, toolbar, and entry in the taskbar. Therefore, an SDI is not constrained to a parent window. This makes it easier for the user to view/edit the contents of the windows.
- Notepad & MS-Paint applications are examples of common SDI applications.
- Multiple Document Interface (MDI):
- MDI is an application software Interface/GUI tool that opens more than one document each time in its primary window without prompting to close the previously opened one.
- MDI contains/controls multiple documents at a time, appearing as a child window. Thus, MDI supports/handles many applications at a time according to the user’s requirements, and hence, fast processing.
- MDI may switch from one or other documents as needed.
- The MDI has a parent window and may contain any number of child windows. The child windows usually share various parts of the parent window’s interface, including the menu bar, toolbar, and status bar.
- Microsoft Visual Studio, MS Word, MS Excel, etc are MDI applications.
- Characteristics of MDI Components in VB .NET
- MDI Parent and Child Relationship
- An MDI application consists of one MDI parent form and one or more MDI child forms, where child forms are displayed inside the parent form.
- Single Parent Window
- The MDI parent form acts as the main container that controls all child windows.
- It is always open while child forms are created, opened, or closed.
- IsMdiContainer Property
- A normal form becomes an MDI parent form when its IsMdiContainer property is set to True.
- MdiParent Property
- Each child form is linked to the parent form using the MdiParent property, which defines where the child form will be displayed.
- Shared Menu System
- MDI applications support menu merging, where menus of child forms are merged with the parent form’s menu.
- Window Management Features
- The MDI parent can arrange child windows in several ways using options like Cascade, Tile Horizontal, and Tile Vertical.
- Centralized Control
- All child forms are managed centrally through the parent form, which improves application organization.
- Improved User Navigation
- Users can easily switch between multiple documents or forms within the same application window.
- Event Handling Support
- The parent form can monitor and control events occurring in child forms.
- MDI Parent and Child Relationship
- Steps to Create MDI Forms in VB .NET
- Step 1: Start Visual Studio, say the 2013 version
- Open Visual Studio 2013 from the Start menu.
- Step 2: Create a New Project
- Click on File – New – Project.
- Select Visual Basic from the left panel.
- Choose ‘Windows Forms Application’.
- Enter a project name and click OK.
- Step 3: Designate the MDI Parent Form
- The default form (Form1) will open in the designer.
- Select Form1, go to the Properties window, and set the IsMdiContainer property to True.
- This converts Form1 into an MDI parent form.
- Step 4: Add a Child Form
- Right-click on the project in Solution Explorer.
- Click Add → Windows Form.
- Name the form (for example, Form2) and click Add.
- This form will act as an MDI child form.
-
Step 5: Create a Menu or Button to Open the Child Form
-
Add a MenuStrip or Button to the MDI parent form (Form1). This control will be used to open the child form.
-
-
Step 6: Write Code to Open the Child Form
-
Double-click the menu item or button and write the following code:
-
- Step 1: Start Visual Studio, say the 2013 version
Dim child1 As New Form2
child1.MdiParent = Me
child1.Show()
-
-
- Step 7: Run the Application
- Press F5 to run the program.
- Step 7: Run the Application
-
The child form will open inside the MDI parent form.
Windows Form Examples
Example : A Windows Forms and Examples in VB .Net 2013 to display a Static Simple Message on pressing a Button.
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
MsgBox("Welcome New Year 2023")
End Sub
End Class
NB: Open a VB 2013 Window application first - Create a new project(as WindowApplication1) - Now, Create a new Form(as Form1) - Draw a button on to the Form(as button1) - Double click on the button - Now write the code as above - Run the code by pressing F5/start button from the standard toolbar - Output appears.
Example : Create a Window Form Application in VB .Net 2013 to display a Static Simple Message in a Text Box on pressing a Button.
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
TextBox1.Text = "Welcome New Year 2023"
End Sub
End Class
Example : Create a Window Form Application in VB .Net 2013 to display the Addition result of two values in a Text Box on pressing a Button.
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
TextBox3.Text = Val(TextBox1.Text) + Val(TextBox2.Text)
End Sub
End Class
Example : Create a Window Form Application in VB .Net 2013 to display all the numbers from 1 to 10 using a For loop in a Text Box on pressing a Button.
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim i As Integer
For i = 1 To 10
TextBox1.Text = TextBox1.Text & " " & i
Next
End Sub
End Class
Example : Create a Windows Form Application in VB .Net 2013 to display all the numbers from 100 to 10 with an interval of 5 using a For loop in a Text Box on pressing a Button.
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim i As Integer
For i = 100 To 10 Step -5
TextBox1.Text = TextBox1.Text & " " & i
Next
End Sub
End Class
Example : Create a Windows Form Application in VB .Net 2013 to display all the numbers between two numbers given by the user at run time(dynamic value) using a For loop in a Text Box on pressing a Button.
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim i As Integer
For i = TextBox1.Text To TextBox2.Text Step 1
TextBox3.Text = TextBox3.Text & " " & i
Next
End Sub
End Class
Example : Create a Windows Form Application in VB .Net 2013 to display the Reverse of the accepted numbers from the user at run time(dynamic value) using a while loop in a Text Box on pressing a Button.
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim x As Integer = Val(TextBox1.Text)
Dim y, result As Integer
While x > 0
y = x Mod 10
result = result * 10 + y
x = x \ 10
End While
TextBox2.Text = result
End Sub
End Class
Example : Create a Windows Form Application in VB .Net 2013 to display the Reverse of the accepted numbers from the user at run time(dynamic value) through User Defined Function using a While loop in a Text Box on pressing a Button.
Public Class Form1
Public Function Reverse(x2 As Integer)
Dim y, result As Integer
While x2 > 0
y = x2 Mod 10
result = result * 10 + y
x2 = x2 \ 10
End While
Reverse = result
End Function
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim x1 As Integer = Val(TextBox1.Text)
TextBox2.Text = Reverse(x1)
End Sub
End Class
![]()
0 Comments