Alternate Application.Run Winform in the Program.cs file

I have a project from two Winform, and I want to run the application in an alternative form. In the program.cs file there is:

Application.Run(new Form1());

This means that Form1 will run as the main form or application launch form. Is it possible to programmatically change it for a certain period or for a limit of days? I mean, in two days, it will execute Form2 as a launch form. As below:

Application.Run(new Form2());

Is it possible?

+3
source share
3 answers

Of course, this is not a problem:

var startDate = ReadStartDateFromFile();
if(DateTime.Now.Subtract(startDate).TotalDays < 2 || startDate == new DateTime())
    Application.Run(new Form1());
else
    Application.Run(new Form2());

ReadStartDateFromFile . , new DateTime().
, , . , , . , , . - , Form2.

Mark !

+7
if(someRuleToDetermineIfForm1NeedsToRun)
{
  Application.Run(new Form1());
}
else if(someRuleToDetermineIfForm2NeedsToRun)
{
  Application.Run(new Form2());
}
else // default
{
  Application.Run(new Form1());
}
+2

; :

if (condition1)
    Application.Run(new Form1());
else
    Application.Run(new Form2());

..

+1

Source: https://habr.com/ru/post/1794723/


All Articles