Solved

C# - Changing MDIParent propertied

Posted on 2011-03-02
5
805 Views
Last Modified: 2013-12-17
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
Comment
Question by:Pandemonium1x
  • 3
  • 2
5 Comments
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 250 total points
ID: 35019043
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
 
LVL 4

Author Comment

by:Pandemonium1x
ID: 35019063
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
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 35019114
Ok, that would suggest that your form isn't actually an MDI Child form. Should it be?
0
 
LVL 4

Author Comment

by:Pandemonium1x
ID: 35019142
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
 
LVL 4

Author Closing Comment

by:Pandemonium1x
ID: 35019147
Great work
0

Featured Post

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Get month and date in a format 4 44
linq, c# 8 31
Problem to Office 1 39
Web page design problem 3 10
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question