/************************************
Part 1 -> Dialog box result
************************************/
// this is a the sample form I put together as a "login" form
// I changed it out to be a dialog box
public partial class LoginForm : Form
{
public LoginForm()
{
InitializeComponent();
// initialize the Dialog Result for you Login Form
this.DialogResult = DialogResult.None;
}
private void button1_Click(object sender, EventArgs e)
{
// this is where you set the result of the login attempt as a dialog result
this.DialogResult = DialogResult.OK;
// on login failure exit gracefully (or allow retry)
//this.DialogResult = DialogResult.Cancel;
}
}
/************************************
Part 2 show MDIForm based on DialogResult
************************************/
static class Program
{
///
/// The main entry point for the application.
///
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
// declare and initialize your mdiForm
MDIForm mdiForm = new MDIForm();
mdiForm.WindowState = FormWindowState.Maximized;
LoginForm loginForm = new LoginForm();
if (loginForm.ShowDialog(mdiForm) == DialogResult.OK)
{
// Application.Run will handle the calls to show and activate
Application.Run(mdiForm);
}
}
}
|