I'm new to c# and I have a program that has two forms. (MainForm) which is the main program form and a license form (FrmLicense) which is the license form for the program. The license form needs to display first if the program is in evaluation mode, otherwise I want the MainForm to display on startup. I put this code in the Main().
internal static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
if (EvaluationMonitor.CurrentLicense.LicenseStatus == LicenseStatus.Licensed)
{
//Run the Main Form
Application.Run(new MainForm());
}
else
{
//Open the License Form
Application.Run(new FrmLicense());
}
}
When the program starts, the license file displays as it should without issue, because no license file is found in the directory. The license file has two buttons, BtnEvaluate and BtnExit. I placed this code in the Evaluation button.
private void BtnEvaluate_Click(object sender, EventArgs e)
{
MainForm mainForm = new MainForm();
mainForm.Show();
//Close the Evaluation Form
Close();
}
Clicking BtnEvaluate causes the license form to momentarily freeze, then MainForm opens briefly, then all the forms disappear. Is this correct or do I need to Call Application.Run(new MainForm()); from the license dialog to open the mainform if the license is in evaluation mode? What am I doing wrong here?
Thanks For your help
internal static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
if (EvaluationMonitor.CurrentLicense.LicenseStatus == LicenseStatus.Licensed)
{
//Run the Main Form
Application.Run(new MainForm());
}
else
{
//Open the License Form
Application.Run(new FrmLicense());
}
}
//Code in FrmLicense
private void BtnEvaluate_Click(object sender, EventArgs e)
{
MainForm mainForm = new MainForm();
mainForm.Show();
//Close the Evaluation Form
Close();
}