check whether form is already opened
-
Saturday, October 28, 2006 9:01 AM
I want to check whether form is already opened, if yes, bring it to front, otherwise, create the new form and open it:
frmRegistration frmRegistration1 = new frmRegistration();
frmRegistration1.Show();please help. It's a C#.net 2005 winform application
All Replies
-
Saturday, October 28, 2006 11:23 AMModerator
Try this:
private frmRegistration regForm;
private void button1_Click(object sender, EventArgs e) {
if (regForm == null) {
regForm = new frmRegistration();
regForm.FormClosed += RegistrationClosed;
regForm.Show(this);
}
regForm.Focus();
}
private void RegistrationClosed(object sender, EventArgs e) {
regForm = null;
} -
Saturday, October 28, 2006 4:39 PM
thx nobugz, thats exactly what i was looking for. i did a little change, this is my code:
if ( Properties.Settings.Default.frmReg == null )
{
Properties.Settings.Default.frmReg = new frmRegistration();
Properties.Settings.Default.frmReg.Show( this );
}
else if ( Properties.Settings.Default.frmReg != null && Properties.Settings.Default.frmReg.WindowState == FormWindowState.Minimized)
{
Properties.Settings.Default.frmReg.WindowState = FormWindowState.Normal ;
}
else
{
Properties.Settings.Default.frmReg.Focus();
}In my case i created the form object in application settings
thx again


