Click here to Skip to main content
15,906,081 members
Please Sign up or sign in to vote.
1.24/5 (3 votes)
See more:
how to access methods of mdi forms while convert string to form object in c# window application
Posted
Comments
renish patel 30-May-13 7:24am    
Hi romal,

May be you are trying to call method from another form,am i right?
Sunasara Imdadhusen 30-May-13 7:32am    
Please provide more details about your question so other can give correct answers!
Romal from Surat Gujarat, India 30-May-13 7:35am    
yes..
renish patel 30-May-13 7:41am    
ok i explain some basic details regarding to your question..follow it carefully,may be you get your solution,if problem occurs then share it.

Thanks

Happy coding...

Here, i give you explanation with taking timer as example.

An MDI child for has a reference to its parent in its MdiParent property. This property is of type Form, so you must cast it to its mpst specific type to get access to members of that type. If your parent form is of type Form1 and it has a Timer named Timer1, you would start that Timer from an MDI child form like this:
C# Code:

((Form1)this.MdiParent).Timer1.Start()

If you have Option Strict turned Off, you can do it without the cast, but that will be using late-binding so Intellisense will not show you the Timer1 property. With Option Strict turned On, as it should always be without good reason not to, the code will not compile without the cast.

If your child form is not an MDI child then you need to give it a reference to the parent form yourself.

Also, I always recommend that all controls be declared Private (the default is Friend) and that you provide access if necessary via public properties and methods of the form. For instance, in this case you would make the Timer private and then provide public methods to start and stop it. That way. your MDI children have enough access to do what they need to but nothing more.
 
Share this answer
 
v2
Comments
Romal from Surat Gujarat, India 30-May-13 7:50am    
i m having one child form from that i m accessing MDI form like
Type t = Type.GetType("namespace" + "MdiFormName");
Form c = Activator.CreateInstance(t) as Form;


Now i want to call one method of MDI form from my chile form.
renish patel 30-May-13 7:55am    
Public Sub New(ByRef PassedForm As Main)
InitializeComponent()
mn = PassedForm

may be this can solve your problem..
Romal from Surat Gujarat, India 30-May-13 8:00am    
i can't understand ur ans.
renish patel 30-May-13 8:25am    
The MDI Parent Form :
A) Making the Methods Public

Public Sub Enable()

SpecialToolStripMenuItem.Enabled = True

End Sub


B) Calling the Method from an MDI Child.This code will be written in the child form where you want the parent form method to be called.


Dim f As Form1 = Me.MdiParent

f.Enable()

Me.Close()
renish patel 30-May-13 8:28am    
and also i share some link for your reference,may be you getting your reply...

https://groups.google.com/forum/?fromgroups#!topic/DotNetDevelopment/qq0mVYVmL7Y
http://www.tek-tips.com/viewthread.cfm?qid=1298195

Thanks
Type t = Type.GetType("namespace" + "MdiFormName");

MethodInfo method = t.GetMethod("CalluserRights");

Form c = Activator.CreateInstance(t) as Form;

//will call CalluserRights method of MDI and return datatable
object datatable = method.Invoke(c, null);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900