• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 810
  • Last Modified:

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?
0
Pandemonium1x
Asked:
Pandemonium1x
  • 3
  • 2
1 Solution
 
Carl TawnSystems 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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now