Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. MdiParent problem [modified]

MdiParent problem [modified]

Scheduled Pinned Locked Moved C#
helpquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Kasic Slobodan
    wrote on last edited by
    #1

    Iam working on MDI application and I have some problem. For the main form, IsMdiContainer is set to true as well as the MdiParent for child form, is set to 'this' (main form). But problem starts here. I put all the codes for each controls in each separete class so it's easy to manipulate. In Tabs class, I have all the methods, properties I need for adding, removing, renaming etc. tabs. I also have a method for adding new child forms. In this method, MdiParent isn't set to 'this', but to frmMain.ActiveForm. The thing is that everything works great unless I try to add new tab from the other Form. App then breaks at line MdiParent = frmMain.ActiveForm with this error: Form that was specified to be the MdiParent for this form is not an MdiContainer. Parameter name: value. How can I workaround this problem, but still have this method for adding new child forms in Tabs class? Iam out of ideas. Sorry if my post is confusing.

    A 1 Reply Last reply
    0
    • K Kasic Slobodan

      Iam working on MDI application and I have some problem. For the main form, IsMdiContainer is set to true as well as the MdiParent for child form, is set to 'this' (main form). But problem starts here. I put all the codes for each controls in each separete class so it's easy to manipulate. In Tabs class, I have all the methods, properties I need for adding, removing, renaming etc. tabs. I also have a method for adding new child forms. In this method, MdiParent isn't set to 'this', but to frmMain.ActiveForm. The thing is that everything works great unless I try to add new tab from the other Form. App then breaks at line MdiParent = frmMain.ActiveForm with this error: Form that was specified to be the MdiParent for this form is not an MdiContainer. Parameter name: value. How can I workaround this problem, but still have this method for adding new child forms in Tabs class? Iam out of ideas. Sorry if my post is confusing.

      A Offline
      A Offline
      Andrew Lygin
      wrote on last edited by
      #2

      Hi, ActiveForm is a static property of the Form class that returns currently activated form for the application but not the acitve frmMain instance. So in some cases you try to bind child form to the non-MDI-parent form. To have access to your frmMain form from all your classes you can add static property to it (as in the Singleton pattern):

      class frmMain
      {
      private static frmMain current;
      public static frmMain Current
      {
      get
      {
      return current;
      }
      }
      public frmMain()
      {
      // constructor logic here
      current = this;
      }
      }

      Then you can use this property to construct your MDI-child forms:

      childForm.MDIParent = frmMain.Current;

      K 1 Reply Last reply
      0
      • A Andrew Lygin

        Hi, ActiveForm is a static property of the Form class that returns currently activated form for the application but not the acitve frmMain instance. So in some cases you try to bind child form to the non-MDI-parent form. To have access to your frmMain form from all your classes you can add static property to it (as in the Singleton pattern):

        class frmMain
        {
        private static frmMain current;
        public static frmMain Current
        {
        get
        {
        return current;
        }
        }
        public frmMain()
        {
        // constructor logic here
        current = this;
        }
        }

        Then you can use this property to construct your MDI-child forms:

        childForm.MDIParent = frmMain.Current;

        K Offline
        K Offline
        Kasic Slobodan
        wrote on last edited by
        #3

        Thank you Andrew, very much. It works like a clock. I've tried something similar, but mine wouldn't work :). I've used other class for this, and it happened nothing, no error, no action, no anything :). And again, thanks.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups