1

I have an windows forms app which is creating controls based on string.

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

But I am getting t as null.

2 Answers 2

2

You can use this code - based on Activator.CreateInstance method

var textBoxType = typeof(Control).Assembly.GetType("System.Windows.Forms.TextBox", true);
var textBox = Activator.CreateInstance(textBoxType);

Link : http://msdn.microsoft.com/fr-fr/library/system.activator.createinstance(v=vs.80).aspx

Sign up to request clarification or add additional context in comments.

Comments

1

You can specify the full name of the assembly (as this one is in the GAC), like this (it will also get back the good assembly even in framework 4):

Type.GetType("System.Windows.Forms.TextBox, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.