open a form generically from a string (name of form)

  • Thread starter Thread starter Sanjay Minni
  • Start date Start date
S

Sanjay Minni

Hi

I have several different types of form
e.g.
- custmaster
- prodmaster
- invoice

all inherited from different form types

How can I open any form generically
if I have the form name given as a string
(at runtime)

How can I trap an error In case the string does
not represent a form name or is of an abstract form type

Regards
Sanjay Minni
www.assetage.com
 
Sanjay,
You can use switch statement for string given, so you can capture a wrong
string .


Best regards,
Vuong
Tran Xuan
 
1-read string and call 'Type ty=Type.GetType("className,AssemblyName");
2-check if type is not null
3-call Form f=(Form)Activator.CreateInstance(ty,constructor parameters);
4-call f.Show()

Dincer Uyav
 
Hi,

Are those the name of the types(classes) ?
If so and they are declared in the same assembly you can use CreateInstance

Or just use a switch statement as suggested by the other opster.


cheers,
 
Back
Top