Hi all.

I would like to know how can I code form1 to open form2 immediately when form1 loaded in Visual Basic?

eg. Form1 opens and immediately form2 opens.

This is almost like website redirection.

Thanks.

Recommended Answers

All 5 Replies

Hi
You call and initiate the second form, from the first forms load event:

Sub Form1_Onload ( byval sender as object, byval e as system.eventargs) Handles Form1.OnLoad
    dim NewForm as new Form2
    NewForm.Show()
    '....
End Sub

Using this technique, you can even set values of controls (or add new controls,) in the second form.

dim NewForm as new form2
'assume there is a textbox txtEntry on Form2
NewForm.txtEntry.Text ="Hello I'm on Form 2" 
NewForm.Show() 'Form2 will open with the textbox populated

You can even open the second form as a modal dialog and process results.

Dim NewForm as New Form2

If NewForm.ShowDialog = DialogResult.OK then
    'Result of OK was returned
Else
    'Other Result
end if

On your second form you would probably have a button that would set the dialog result of the form to OK provided what you wanted to happen on the form happened.

simply just paste the code in the form 1 load event
form2.show
if you want to load as dialog then put this code:
form2.showdialog
and as to create new form from form 1 then

Dim Nform as new Form
Nform.show
Nform.text = "Form2: Title"
...
....

You have done.
if this is not your question then please elaborate this

hi i hope it could be help you

1.Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
2 Form2.Show()
3 Form2.WindowState = FormWindowState.Normal
4 Form2.BringToFront()
5 End Sub

by: Rossana kaw

@Mafiamanandre:
Can you tell whether this discussion solve your quries or not?
if yes then please mark it as solve
if not then tell what you don't get it

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.