Hi Can I create a Control from String Value Like
from "System.Windows.Forms.TextBox" create control
Hi Can I create a Control from String Value Like
from "System.Windows.Forms.TextBox" create control
You could use reflection:
var textBoxType = typeof(Control).Assembly.GetType("System.Windows.Forms.TextBox", true);
var textBox = Activator.CreateInstance(textBoxType);
textBoxType.GetProperty("Text").SetValue(textBox, "Hello World", null);. I would recommend you reading more about reflection: msdn.microsoft.com/en-us/library/f7ykdhsy.aspxDo like this :
var controlType = typeof(Control);
var type = controlType
.Assembly
.GetTypes()
.Where(t => controlType.IsAssignableFrom(t) &&
t.Namespace == "System.Windows.Forms"
t.Name == "ControlName"
).FirstOrDefault();
var inst = Activator.CreateInstance(type );
This answer is because of your previous question.