Solved

C# - Changing MDIParent propertied

Posted on 2011-03-02
5
807 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

636 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