You are on page 1of 4

9.

CREATING A NEW FORMS AND CONTROLS DURING RUNTIME


AIM:
To create new forms manually using vb.net.

PROCEDURE:
1. 2. 3. 4. 5. Open the vb and then create the forms with buttons like create new form. For creating date and current time in the forms automatically generating. By using the position on the rectangular form we can also insert a lable manually. Hence the format for the staring screen position is also included manually. Hence output the program and run it.

CODING:
Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim form2 As New Form form2.Text = "ok" form2.FormBorderStyle = Windows.Forms.FormBorderStyle.FixedDialog form2.StartPosition = FormStartPosition.Manual Dim form2rect As New Rectangle(200, 100, 300, 250) form2.DesktopBounds = form2rect form2.ShowDialog() End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Dim form2 As New Form Dim bt As New Button Dim tb As New TextBox Dim lbl As New Label lbl.Text = "current date is :" tb.Text = DateString tb.Location = New Point(20, 60) lbl.Size = New Size(150, 50) lbl.Location = New Point(40, 10) bt.Text = "cancel" bt.Location = New Point(110, 100) form2.Text = "current date" form2.CancelButton = bt form2.StartPosition = FormStartPosition.CenterScreen form2.Controls.Add(lbl)

form2.Controls.Add(bt) form2.Controls.Add(tb) form2.ShowDialog() End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click Dim form2 As New Form Dim bt1 As New Button Dim tb1 As New TextBox Dim lbl1 As New Label lbl1.Text = "current time is :" tb1.Text = TimeOfDay tb1.Location = New Point(20, 60) lbl1.Size = New Size(150, 50) lbl1.Location = New Point(40, 10) bt1.Text = "cancel" bt1.Location = New Point(110, 100) form2.Text = "current time" form2.CancelButton = bt1 form2.StartPosition = FormStartPosition.CenterScreen form2.Controls.Add(lbl1) form2.Controls.Add(bt1) form2.Controls.Add(tb1) form2.ShowDialog() End Sub End Class

INPUT FORM:

OUTPUT FORM:

RESULT:
Thus the new forms were created manually and controls at runtime successfully.

You might also like