PC Review Forums Newsgroups Microsoft DotNet Microsoft Dot NET Compact Framework How to get a Form object through the form name

Reply

How to get a Form object through the form name

 
Thread Tools Rate Thread
Old 12-09-2006, 01:56 PM   #1
Hari
Guest
 
Posts: n/a
Default How to get a Form object through the form name


Hi,
I need to get a form instance, by supplying the form name i.e, i
need some thing similar to Class.forName() in Java. I tried it using
System.Type.GetType() method passing the form name as object. But the
prob here is i'm getting an exception saying "System.Type can not be
casted to a System.Windows.Form". How can i get the form object based
on the form name. Any one plz suggest.

Thanks,

Hari

  Reply With Quote
Old 12-09-2006, 04:05 PM   #2
Guest
 
Posts: n/a
Default Re: How to get a Form object through the form name

Use a variation of my GetControlByName function:

http://blog.opennetcf.org/ctacke/Pe...1a-2ae2de4bdaf1


--
Chris Tacke
OpenNETCF Consulting
Managed Code in the Embedded World
www.opennetcf.com
--


"Hari" <hadusumalli@mantragroup.com> wrote in message
news:1158065775.428204.317710@e63g2000cwd.googlegroups.com...
> Hi,
> I need to get a form instance, by supplying the form name i.e, i
> need some thing similar to Class.forName() in Java. I tried it using
> System.Type.GetType() method passing the form name as object. But the
> prob here is i'm getting an exception saying "System.Type can not be
> casted to a System.Windows.Form". How can i get the form object based
> on the form name. Any one plz suggest.
>
> Thanks,
>
> Hari
>



  Reply With Quote
Old 12-09-2006, 04:29 PM   #3
Hari
Guest
 
Posts: n/a
Default Re: How to get a Form object through the form name

Hi Chris,
Thanks for the suggestion. I've already downloaded your class
previously. That was working fine, but for controls other than a Form.
As you have used Parent property which is null for a Form, this does
not work on a Form as it is. Please suggest what has to be modified to
make it work for a Form.
<ctacke/> wrote:
> Use a variation of my GetControlByName function:
>
> http://blog.opennetcf.org/ctacke/Pe...1a-2ae2de4bdaf1
>
>
> --
> Chris Tacke
> OpenNETCF Consulting
> Managed Code in the Embedded World
> www.opennetcf.com
> --
>
>
> "Hari" <hadusumalli@mantragroup.com> wrote in message
> news:1158065775.428204.317710@e63g2000cwd.googlegroups.com...
> > Hi,
> > I need to get a form instance, by supplying the form name i.e, i
> > need some thing similar to Class.forName() in Java. I tried it using
> > System.Type.GetType() method passing the form name as object. But the
> > prob here is i'm getting an exception saying "System.Type can not be
> > casted to a System.Windows.Form". How can i get the form object based
> > on the form name. Any one plz suggest.
> >
> > Thanks,
> >
> > Hari
> >


  Reply With Quote
Reply



Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off