How to Enable a parent menu from child class?
-
Hi, I want to enable a menu, which is in main class, against any child class function but it is not activating. Instead If I enable it against any button of main class it becomes enable. as here udb-main is main class and from its button of start I open another form like:
private void bstart_Click(object sender, EventArgs e) { UserLogin uslog = new UserLogin(); uslog.Show(); }
Now in userlogin class login button I want to active main class activities menu against successful login.Here just relevant code is:private void bLogin_Click(object sender, EventArgs e) { DialogResult ds; ds = MessageBox.Show(" you are successfully login ","Login Success", MessageBoxButtons.OKCancel); if (ds == DialogResult.Cancel) this.Close(); else if (ds == DialogResult.OK) { udb-main hmain=new udb-main();// Main class **hmain.activitiesToolStripMenuItem.Enable=true;** hmain.hessloadfunc(); this.Close(); } }
plz tell me how I can enable/disable any control from another class. Thanx.Shanzay
-
Hi, I want to enable a menu, which is in main class, against any child class function but it is not activating. Instead If I enable it against any button of main class it becomes enable. as here udb-main is main class and from its button of start I open another form like:
private void bstart_Click(object sender, EventArgs e) { UserLogin uslog = new UserLogin(); uslog.Show(); }
Now in userlogin class login button I want to active main class activities menu against successful login.Here just relevant code is:private void bLogin_Click(object sender, EventArgs e) { DialogResult ds; ds = MessageBox.Show(" you are successfully login ","Login Success", MessageBoxButtons.OKCancel); if (ds == DialogResult.Cancel) this.Close(); else if (ds == DialogResult.OK) { udb-main hmain=new udb-main();// Main class **hmain.activitiesToolStripMenuItem.Enable=true;** hmain.hessloadfunc(); this.Close(); } }
plz tell me how I can enable/disable any control from another class. Thanx.Shanzay
DeepOceans wrote:
else if (ds == DialogResult.OK) { udb-main hmain=new udb-main();// Main class hmain.activitiesToolStripMenuItem.Enable=true; hmain.hessloadfunc(); this.Close(); }
You have to assign the parent class to the
hmain
field instead of assigning a new instance. Most probably it has to beudb-main hmain = (udb-main)this.Parent;// Main class
. BTW the architecture which is changing the state of a parent element does not seems to be good.*jaans
-
DeepOceans wrote:
else if (ds == DialogResult.OK) { udb-main hmain=new udb-main();// Main class hmain.activitiesToolStripMenuItem.Enable=true; hmain.hessloadfunc(); this.Close(); }
You have to assign the parent class to the
hmain
field instead of assigning a new instance. Most probably it has to beudb-main hmain = (udb-main)this.Parent;// Main class
. BTW the architecture which is changing the state of a parent element does not seems to be good.*jaans
I did it, but now it is giving error:Set object refrence exception..... Tell another solution.Plzzz
Shanzay
-
Hi, I want to enable a menu, which is in main class, against any child class function but it is not activating. Instead If I enable it against any button of main class it becomes enable. as here udb-main is main class and from its button of start I open another form like:
private void bstart_Click(object sender, EventArgs e) { UserLogin uslog = new UserLogin(); uslog.Show(); }
Now in userlogin class login button I want to active main class activities menu against successful login.Here just relevant code is:private void bLogin_Click(object sender, EventArgs e) { DialogResult ds; ds = MessageBox.Show(" you are successfully login ","Login Success", MessageBoxButtons.OKCancel); if (ds == DialogResult.Cancel) this.Close(); else if (ds == DialogResult.OK) { udb-main hmain=new udb-main();// Main class **hmain.activitiesToolStripMenuItem.Enable=true;** hmain.hessloadfunc(); this.Close(); } }
plz tell me how I can enable/disable any control from another class. Thanx.Shanzay
There is a small change required in both of the functions, we can use
Owner
instead ofParent
private void bstart_Click(object sender, EventArgs e)
{
UserLogin uslog = new UserLogin();
uslog.Show(this);
}and
else if (ds == DialogResult.OK)
{
udb-main hmain = (udb-main)this.Owner;// Main class
hmain.activitiesToolStripMenuItem.Enable=true;
hmain.hessloadfunc();
this.Close();
}Please try this.
*jaans
-
There is a small change required in both of the functions, we can use
Owner
instead ofParent
private void bstart_Click(object sender, EventArgs e)
{
UserLogin uslog = new UserLogin();
uslog.Show(this);
}and
else if (ds == DialogResult.OK)
{
udb-main hmain = (udb-main)this.Owner;// Main class
hmain.activitiesToolStripMenuItem.Enable=true;
hmain.hessloadfunc();
this.Close();
}Please try this.
*jaans
Thank u so much. It did work now ;) Now plz tell me abt my 1 more prob. if u can. When I click Disconnect button it throws exception and application dont close all threads which are using in main as well as its other classes. private void bDisconect_Click(object sender, EventArgs e) { try { Client_Login clog = new Client_Login();//child class clog.clnt_th.Abort();//child class thread clog.sock.Close();//child socket function } catch(System.NullReferenceException expnul) { MessageBox.Show(expnul.Message); } } Here what is the main prob.? How to finish this thread exactly.
Shanzay