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

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
 
V

Vuong

Sanjay,
You can use switch statement for string given, so you can capture a wrong
string .


Best regards,
Vuong
Tran Xuan
 
G

Guest

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
 
I

Ignacio Machin \( .NET/ C# MVP \)

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,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top