C# String to variable name -
hi trying set richtextbox variable name textbox string name possible?
public void addtab(string name) { tabpage newpage = new tabpage(name); richtextbox textbox = new richtextbox(); textbox.gettype().getproperty("name").setvalue(textbox, name,null); this.tabcontrol1.tabpages.add(newpage); newpage.controls.add(textbox); textbox.location = new system.drawing.point(0, 0); textbox.name = name; textbox.size = new system.drawing.size(790, 460); textbox.tabindex = 0; textbox.text = ""; }
i don't think possible local variables, it's possible in member variables of object using reflection. if go route, there lots of articles in msdn knowledge base setting properties reflection.
however, reflection expensive do, there might better ways implement design. 1 possibility springs mind use dictionary string keys.
Comments
Post a Comment