-1

How do I re-enable a Menu in MainForm from Second Form?

I use

 private void AnalysisForm_FormClosing(object sender, EventArgs e)
 {
    HomeForm.checkBeamToolStripMenuItem.Enabled = true;
 }

But it says

HomeForm.checkBeamToolStripMenuItem is inaccessible due to its protection level

I'm not sure which part of my code should I declare as Public.

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
Tramyer
  • 13
  • 1
  • 8
  • The error message tells you exactly what you need to make public: `HomeForm.checkBeamToolStripMenuItem`. – Cody Gray - on strike Jun 12 '17 at 12:49
  • Hi Cody I just changed my Modifier menu into public and now i'm getting this "CS0120 An object reference is required for the non-static field, method, or property 'HomeForm.checkBeamToolStripMenuItem" How do I provide static method in my coding? thanks in advance – Tramyer Jun 18 '17 at 12:01

1 Answers1

0

protection level for your checkBeamToolStripMenuItem in MainForm will be private by default, you need to make that as public or internal so that it could be accessed in other classes,

to make your control public, select your control -> properties -> modifier ( change it to public from private )

and you need to pass the current instance of your Mainform to Second Form and access the control through that instance.

Vicky S
  • 762
  • 4
  • 16
  • Now my modifier is internal/public tried both. I got this error "CS0120 An object reference is required for the non-static field, method, or property 'HomeForm.checkBeamToolStripMenuItem" – Tramyer Jun 18 '17 at 11:35
  • you can fix this in 2 ways, 01) initialize the control in your HomeForm Constructor if the control is added through code, 02) or you can remove your code from cs and drag menustrip control from tools in the designer and do not forget to update the modifier. – Vicky S Jun 19 '17 at 05:11