stu nicholls dot com | menu - Professional dropdown #3

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
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
Minimizing/Maximizing forms

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


comments powered by Disqus
Footer1