I want to load a welcome screen on the startup of the application then the user clicks a button on the welcome screen and then closes the welcome screen. Finally then shows the main screen.
static void Main() //startup method being called
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new ACM812_DB()); // welcome screen
}
When a button is clicked on the welcome screen it then hides the welcome window and then brings up the main window. As shown below.
private void button1_Click(object sender, EventArgs e)
{
Form1 form1 = new Form1();
form1.Show(); // main window
this.Hide();
}
It does work successfully but is it the correct way to implement this?
Updated code:
Main form startup (MainForm.cs)
namespace System
{
public partial class MainForm : Form
{
private void MainForm_Load(object sender, EventArgs e)
{
WelcomeForm.Run(this);
}
public MainForm()
{
InitializeComponent();
}
}
}
Welcome screen then called
public partial class WelcomeForm : Form
{
static private Form Sender;
static public void Run(Form sender)
{
if (sender == null)
throw new ArgumentNullException();
Sender = sender;
new WelcomeForm().ShowDialog();
}
private void ButtonClose_Click(object sender, EventArgs e)
{
Close();
}
}