Accept and Cancel Button

Now let us add some code to the dialog box, Form2, to close the dialog box when the user clicks the button.
We will set the dialog box’s AcceptButton and CancelButton properties to indicate which button is the accept button and which is the Cancel button, this allows the user to press Enter to select the accept (OK) button , and Esc to select the Cancel button

Creating Owned Forms
  • You can also create owned forms in Visual Basic.
  • An Owned form is tied to the form that owns it; if the user minimizes the owner form, the owned form will also be minimized, and so on.
  • You can add an owned form with the AddOwned form method, and remove an owned form with the RemoveOwnedForm method
  • In the example we will place a button in Form1 as shown in Fig 11 that will make an object of the Form2 class into an owned form and display it which is shown in Fig 12. .
Following is Program for owned form:
Public Class Form1
Dim ownedform1 As New Form2()
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.AddOwnedForm(ownedform1)
ownedform1.Show()
End Sub
End Class



Passing Forms to Procedure
  • You can pass forms to procedures just as you would any object
  • Here we have set up a sub procedure ColorWindowRed, to turn the background color of a form to red using the FormBackColor Property
  • This is a good technique to know if you want to coordinate between forms in a multiform applications
Minimizing/Maximizing forms
  • To exert a little more control over the windows in your program, you can set the WindowState property to maximize or minimize them
    Following are the property
    FormWindowState.Maximized
    FormWindowState.Minimized
    FormWindowState.Normal

Following is the Program:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.WindowState = FormWindowState.Minimized
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Me.WindowState = FormWindowState.Maximized
End Sub
End Class
Adding and Removing Controls at Run Time

You can add or remove controls to your applications at run time. For this use the form’s Control collection’s Add or Remove methods.
In this example let us add a Text box at run time create a text box in code, give it a size and locations, set its text, and use the Add method when the user clicks a button. Refer Fig. 14 and Fig. 15.

Following is the Program:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim NewTextBox As New TextBox()
Dim newListBox As New ListBox()
NewTextBox.Size = New Size(150, 15)
NewTextBox.Location = New Point(50, 50)
NewTextBox.Text = "Hello My Dear Friends Of Final BCA"
Me.Controls.Add(NewTextBox)
newListBox.Size = New Size(175, 35)
newListBox.Location = New Point(50, 100)
newListBox.Text = "Hello My Dear Friends Of 2nd Sem"
Me.Controls.Add(newListBox)
End Sub
End Class





Creating Dialog Boxes<< Previous

Next >> Types of Validation

Our aim is to provide information to the knowledge seekers. 


comments powered by Disqus
Footer1