Changing the main form

  • Thread starter Thread starter Tony
  • Start date Start date
T

Tony

Hi,
How do you change the main form in visual basic .net 2003?

I have a form1 as the startup form. Based on a user response as to
which mode to run the program in, i would like to transfer control of
the program to form2 or form3 and close form1. However, if I close
form1, the application will close because it is the startup form.

I guess I could make form1 hidden and form2 or form3 modal, but i was
hoping there was a better way.

Thanks for you help,
Tony
 
Tony,
I would add a Shared Sub Main to Form1, display Form1 as a dialog, then
based on the result pass a new Form2 or Form3 to Application.Run.

Something like:

Public Class Form1

Public Shared Sub Main
Dim dialog As New Form1
If dialog.ShowDialog() = DialogResult.Ok Then
Dim formMain As Form
If dialog.Response = UseForm2 Then
formMain = New Form2
Else
formMain = New Form3
End If
Application.Run(formMain)
End If
End Sub

Where Response is a property that indicates what the use selected.

Hope this helps
Jay
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top