954,178 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

call function in childform from mdi parent

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??

plastic
Newbie Poster
13 posts since Nov 2009
Reputation Points: 10
Solved Threads: 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?

Ryshad
Nearly a Posting Virtuoso
1,307 posts since Aug 2009
Reputation Points: 512
Solved Threads: 246
 

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

plastic
Newbie Poster
13 posts since Nov 2009
Reputation Points: 10
Solved Threads: 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();
Ryshad
Nearly a Posting Virtuoso
1,307 posts since Aug 2009
Reputation Points: 512
Solved Threads: 246
 

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

plastic
Newbie Poster
13 posts since Nov 2009
Reputation Points: 10
Solved Threads: 0
 

Post the code in question, or zip up the project so we can see what is happening.

DdoubleD
Posting Shark
996 posts since Jul 2009
Reputation Points: 341
Solved Threads: 233
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You