简体   繁体   中英

How to run another windows form on button click in windows form application

I am working on windows form application where i need to upgrade the windows form application software solution based on the licence key provided by the user.Suppose he has upgraded his software from basic to higher version.In this case we want him to enter the upgraded licence key which will be verified from our Central server and the software will be upgraded. For upgrading the software i need to change the main class program file..

Here is the code for program file..

namespace UpgradeECV
{
static class Program
{
    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    [STAThread]
    static void Main()
    {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        Application.Run(new Form1());
    }
}

}

Now as soon as user eneters the correct verified upgraded licence key i want

 Application.Run(new Form1());

to change to

 Application.Run(new Form2());

How can this be possible .. Please help me

With utilizing a simple bool flag that indicates user is licensed or not, you can then Run either Form1 or Form2 , like this:

Form form = isLicensed ? new Form2() : new Form1();
Application.Run(form);

In this case instead of running the Form1() class you can run some other class where you will compare the version and the decide which Form you need to open.

Suppose version is XX then you can open you First form else your second. This way you can achieve this, but I don't see any possibility of changing the code run time.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM