C# - Changing MDIParent propertied

Good afternoon,

I am writing a Windows form C# project and stuck on a simple issue where I am trying to change properties on a MDIParent from a child form and despite that there are no errors the property does not change. So here's the breakdown.

[On MDIParent1]

toolsToolStripMenuItem (Modifier - Public) (Currently set to enabled = false on load)

[On Child form]

Password box with the following code in the OK button.
 
if (txtPassword.Text == "password")
    {
     MDIParent1 parent = new MDIParent1();
     parent.toolsToolStripMenuItem.Enabled = true;
     
      MessageBox.Show("This computer has now been authorized for one session use.", "Access Granted", MessageBoxButtons.OK, MessageBoxIcon.Information);

      this.Close();
      }
      else
      {
     
       MessageBox.Show("You are not authorized to use this program", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Stop);
       }

Open in new window

I did add a break to see if it hits that code and it does but the MDIParent object remains disabled. During my step into of the break it never goes back to anywhere that re-disables the menu item. Any ideas?
LVL 4
Pandemonium1xAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
Carl TawnConnect With a Mentor Systems and Integration DeveloperCommented:
It's because you are creating a new instance of the MDI form rather than accessing the MDI form that your current form belongs to.

Try:
MDIParent1 parent = this.MdiParent as MDIParent1;
parent.toolsToolStripMenuItem.Enabled = true;

Open in new window

0
 
Pandemonium1xAuthor Commented:
I did try that before actually but if I do then it breaks with a NullReferenceException (object reference not set to an instance of an object)
0
 
Carl TawnSystems and Integration DeveloperCommented:
Ok, that would suggest that your form isn't actually an MDI Child form. Should it be?
0
 
Pandemonium1xAuthor Commented:
D'oh! it appears I forgot to add my form.MDIParent = this; on load of the form. You're rank does you justice sir. Thanks, it works now!
0
 
Pandemonium1xAuthor Commented:
Great work
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.