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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Posted May 21, 2011, 8:32 AM
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.
sbo silverPosted May 23, 2011, 1:48 PM
VulpesPosted May 21, 2011, 8:25 AM
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.