mdi

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • siddhanta
    New Member
    • Oct 2009
    • 33

    mdi

    i wanna create a mdi form. but to make the other form as child of the main i cant find any mdiparent property in the properties list. i m using vs 2010.
    help plzzz

    leave it
    i understood how to do it
  • ThatThatGuy
    Recognized Expert Contributor
    • Jul 2009
    • 453

    #2
    It's Simple..... Open up the form you want to make as parent MDI form....

    in the property window of the form.... check out for IsMDIContainer property in this window under Window Style Section..... and then select it to true...


    you will see the background of the form changes and thus,,,, now it becomes a MDI Parent form

    Comment

    • siddhanta
      New Member
      • Oct 2009
      • 33

      #3
      reference to parent form

      hi
      how to get the reference of parent form. Actually i want to call a method of parent form through the child form.

      Comment

      • Frinavale
        Recognized Expert Expert
        • Oct 2006
        • 9749

        #4
        It sounds like you would be interested in researching the topic of Delegates.

        Or, you could do it the way you were thinking.
        Pass a reference to the parent form to the child form using the child form's constructor. Then you will be able to access the parent form from the child form.

        For example:
        Code:
        public partial class Form1 : Form
        {
            public Form1()
            {
               InitializeComponent();
            }
        
            private void button1_Click(object sender, EventArgs e)
            {
                Form2 tempDialog = new Form2(this);
                tempDialog.ShowDialog();
            }
            public void msgme()
            {
                MessageBox.Show("Parent Function Called");
            }
        }
        Child form:
        Code:
        public partial class Form2 : Form
        {
            private Form1 m_parent;
            public Form2(Form1 frm1)
            {
                InitializeComponent();
                m_parent = frm1;
            }
            private void button1_Click(object sender, EventArgs e)
            {
                m_parent.msgme();
            }
        }
        The problem with this approach is that the child form can be used in any form...and the form that it is used in may not have that method to call.

        I think you should at least look into Delegates.
        -Frinny

        Comment

        • tlhintoq
          Recognized Expert Specialist
          • Mar 2008
          • 3532

          #5
          I agree with Frinny. Form2 shouldn't have to know all the methods and properties of Form1.

          Form2 should raise an event, as a signal to Form1 to react and do it's part.
          It isn't the responsibility of Form2 to understand what Form1 needs to do.

          Basically Form2 yells "I'm done"
          Form1 reacts by doing its part, and Form2 couldn't care less what that part is.

          Instead of your archetecture where you have
          Form2 order "Form1 go do this"

          Comment

          Working...