Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Good Day to all.

 

I want to dynamically create a Windows Form using reflection. The test code below is what I used.

 

-------------------------

 

public Form CreateForm()

{

Control control = null;

Type t = Type.GetType("System.Windows.Forms.Form");

if(t != null)

{

control = (Control) Activator.CreateInstance(t);

}

return (Form) control;

}

 

 

-------------------------

 

 

When running the code, the error below is generated...

 

>>>> Could not load type System.Windows.Forms.Form

>>>> from assembly

 

 

Im still new to C# and hope you can give me your expert advice on this issue.

 

Best Regards..... :)

Posted

I think, you must give the GetType-Method

the name of the concrete Form:

E.g. if you have a class, which is derived from

System.Windoes.Forms.Form and which is called

"MyClass", then the code must look like this:

Type t = Type.GetType("MyClass");

 

This way should be the right one, I think.

 

Greetings from Germany!

 

Toni.

Greetings,

 

Toni.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...