Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How to Enable a parent menu from child class?

How to Enable a parent menu from child class?

Scheduled Pinned Locked Moved C#
tutorialquestion
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    DeepOceans
    wrote on last edited by
    #1

    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

    J 2 Replies Last reply
    0
    • D DeepOceans

      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

      J Offline
      J Offline
      J a a n s
      wrote on last edited by
      #2

      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 be udb-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

      D 1 Reply Last reply
      0
      • J J a a n s

        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 be udb-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

        D Offline
        D Offline
        DeepOceans
        wrote on last edited by
        #3

        I did it, but now it is giving error:Set object refrence exception..... Tell another solution.Plzzz

        Shanzay

        1 Reply Last reply
        0
        • D DeepOceans

          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

          J Offline
          J Offline
          J a a n s
          wrote on last edited by
          #4

          There is a small change required in both of the functions, we can use Owner instead of Parent

          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

          D 1 Reply Last reply
          0
          • J J a a n s

            There is a small change required in both of the functions, we can use Owner instead of Parent

            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

            D Offline
            D Offline
            DeepOceans
            wrote on last edited by
            #5

            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

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups