0

hi
i have function in mdiparent form and i want to use it in child form.
i created an object reference of parent form in child form and tried to call the function but this didnt worked.
wat should i do??

3
Contributors
5
Replies
6
Views
7 Years
Discussion Span
Last Post by DdoubleD
0

First of all, C# doesnt have functions, they are methods. I'm on a crusade to eradicate that word from this board ;)

Secondly, how is the method declared, private/public/protected? How have you created your reference to the parent form?

0

kkk its method..
i declared the method as public in parect form
and used the follwing code to call the method in child form
Form1 ob1 = new Form1();//form1 is parent form
ob1.alllblvis();//alllvlvis is the function

0

Theres your problem. You arent getting a reference to your original Form1, you are creating a new one.
You need to get a reference to the original form if you want to effect any changes to it:

Form1 parent = (Form1)this.MdiParent;
parent.alllblvis();

You need to ensure you have set the MDIParent of the second form when you called it:

Form2 newForm = new Form2();
newForm.MdiParent = this;
newForm.Show();
0

hi
i used the second code to make form 1 the parent of the form2 and show it. But the first form in giving an error. its asking for ';' after the 'this' of the first line. i.e. this;mdiparent

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.