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 tha开发者_运维技巧t 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.
I may be misreading your question, but it appears that in your Send button's Click event you're creating a new instance of SecondForm
and calling its function. If you're creating a new instance of the form here, then it's not the same instance of the form that is already sitting in your MDI parent form (which is why nothing appears to be happening).
What you need to do is get a reference to the instance of SecondForm
that is already in your MDI parent form, and call its public method. You can get a reference to the second form via the parent form's MdiChildren
collection, like so:
SecondForm f2 = (SecondForm)this.MdiChildren[1]; // second form in collection
f2.PublicMethod();
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. :-)
精彩评论