Monday, October 30, 2006

check whether form is already opened in C#.net 2k5 winform application

created the form object in application settings

Code to open the form:
private void button1_Click(object sender, EventArgs e) {

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();
}
}

Code to close the opened form:
Properties.Settings.Default.frmReg = null;

No comments: