How to manipulate another form from the other without reseting its values in c#
i want to disenable my mdiparent when my login form appears and re-enable it again if login is successful
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend3days leftRegister
Posted May 21, 2011, 4:32 AM EDT
Please find the attached. In the MDIParent Form, on the Load event I have disabled all the controls except MDIClient form then I 'm displaying the MDIChild forms(login forms).
In the Login Form, we can be able to access the MDIParent,once the login is success, we can enable the controls in the
MDIParent form.
Samplecode :
MDIParent Form
private void MDIParent_Load(object sender, EventArgs e){
EnableDisbleControls(false);
ShowLogin();
}
public void EnableDisbleControls(bool ISEnable){
foreach (Control c in this.Controls)
{
if (c.GetType().ToString() != "System.Windows.Forms.MdiClient")
c.Enabled = ISEnable;
}
}
private void ShowLogin(){
LoginForm frmLogin = new LoginForm();
frmLogin.MdiParent = this;
frmLogin.Show();
}
Login Form:
MDIParent frm = (MDIParent)this.MdiParent;
frm.EnableDisbleControls(true);
this.Close();
Hope this helps you.
VulpesRank #55 · 29.2K pointsPosted May 21, 2011, 4:25 AM EDT
There are a number of ways to obtain this but the following might be best in your particular circumstances.
In the mdiparent class (let's assume it's called Form1), add this static field:
internal static readonly Form1 Me;
and add a line to its constructor to initialize it:
public Form1()
{
InitializeComponent();
Me = this;
}
From the login form you can now do:
Form1.Me.Enabled = false;
and set back to true to re-enable.
sbo silver3 pointsPosted May 23, 2011, 9:48 AM EDT