Aimad MAJDOU

Aimad MAJDOU

  • NA
  • 1
  • 1.2k

how to enable a form from another form

Jul 25 2012 2:11 PM
Hello, I created two forms: a login form, and a main form that is displayed when I start debugging.
when loading the main form the login form also loaded.
Now my question is, I want to disable the main form when the login form is loaded.
if the connection is successful, the main form must be enabled, otherwise it should be disabled.

I tried this code :

MainFrm .cs :
private void Form1_Load(object sender, EventArgs e)
{
foreach (Control c in this.Controls)
c.Enabled = false;
Connectez ConnectezFrm = new Connectez { TopMost = true, Owner = this };
ConnectezFrm.Show();
}

Connectez.cs :
private MainFrm objMainfrm { get; set; }
public Connectez(MainFrm objfrm)
{
objMainfrm = objfrm;
InitializeComponent();
}
....
....
private void simpleButton1_Click(object sender, EventArgs e)
{
foreach (Control c in objMainfrm.Controls)
c.Enabled = true;
this.Close();
}