Search code examples
mdichild

Pass Value between MDI Child in WinForm using C#


I have an MDI Parent, containing a MenuStrip. When I click on one of the Menu, two Child Forms are displayed simultaneoulsy.

I have a TextBox and a Send Button on one of my ChildForm. When I type-in something in that TextBox and Click the Send Button, I need to show that value in the TextBox of my Second Child Form.

What I had done is, I wrote a Public Function in the Second Child Form and tried to invoke it by creating an object of Second Form, on the Send Button click event. When I put break points, in that Public Function, I find that the control is flowing through that Public function on cliking the Send button. But the passed value is not displayed. And, I know that is not the standard way to do that.

Any sample script for help? Thanks.


Solution

  • Thanks for the reply.

    I tried your code, but was giving an error : Index was outside the bounds of the array.

    I changed the code slightly, to make it working, as follows:

    SecondForm f2= (SecondForm)this.MdiParent.MdiChildren[1];
            f2.PublicMethod(some_value_to_pass);
    

    Thanks for the help. :-)