tags:

views:

38

answers:

3

Hi!

I have application in VB.net that have two different form (Form1 and Form2). Now I need to examine some condition and if condition is true then i set Form1 for startup for and if it not then i set Form2 for startup form.

So is there anyway to dynamically call startup form? Thanks!

+1  A: 

If you look in the main execution method (normally Program.cs or Program.vb) you'll see the static Main(string[] args) method. You could then use command line arguments to decide which form to display.

Note the below example is in C# but should give you the general idea.

public static Main(string[] args)
{
    // initialization omitted

    if (args.Length.Equals(0))
    {
        // load form 1
    }
    else if (args[0].Equals("SomeValue", StringComparison.OrdinalIgnoreCase)
    {
        // load form 2
    }
    else 
    {
        // load form 3
    }
}
Kane
A: 

Check the file called Program.vb. That is where the startup form is initialized. You can put your logic there.

klausbyskov
+1  A: 

Change your Main method to something like this:

[STAThread]
static void Main()
{
    Application.EnableVisualStyles();
    Application.SetCompatibleTextRenderingDefault(false);
    if(...condition...)
    {
        Application.Run(new Form1());
    }
    else
    {
        Application.Run(new Form2());
    }
}

This is C# but the principle applies in VB as well.

AZ