1,105,380 Community Members

Automatically open Form 2

Member Avatar
Mafiamanandre
Light Poster
25 posts since Oct 2013
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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.

Member Avatar
G_Waddell
Practically a Posting Shark
821 posts since Nov 2009
Reputation Points: 131 [?]
Q&As Helped to Solve: 137 [?]
Skill Endorsements: 13 [?]
 
0
 

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.

Member Avatar
DM Galaxy
Junior Poster in Training
65 posts since Aug 2013
Reputation Points: -6 [?]
Q&As Helped to Solve: 2 [?]
Skill Endorsements: 5 [?]
 
0
 

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

chuchaykaw
Newbie Poster
8 posts since Nov 2013
Reputation Points: 1 [?]
Q&As Helped to Solve: 2 [?]
Skill Endorsements: 0 [?]
Unverified Member
 
0
 

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

Member Avatar
KimberGariando
Newbie Poster
4 posts since Oct 2013
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
0
 

1.Form2.Show()

Member Avatar
DM Galaxy
Junior Poster in Training
65 posts since Aug 2013
Reputation Points: -6 [?]
Q&As Helped to Solve: 2 [?]
Skill Endorsements: 5 [?]
 
0
 

@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

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: