C # convert string to component name and variable name,
String to component name
(Controls ["button1"] as Button ). text = "Hello"; // separate component (Controls ["tabControl1"]. controls [0]. controls ["performance1"] as TextBox ). text = "111.111.111.111"; // nested component
Variable name of a string
String str = "demo"; // you can write it to the following button#click. demo is the following variable name: public string demo = "Old String"; private void button#click (object sender, EventArgs e) {// obtain the variable value MessageBox through a string. show (this. getType (). getField (str ). getValue (this ). toString (); // display the Old String GetType (). getField (str ). setValue (this, "New String"); MessageBox. show (spp); // display New String MessageBox. show (this. getType (). getField (str ). getValue (this ). toString (); // display New String}
Or
Public string Demo = "Old String"; private void button2_Click (object sender, EventArgs e) {// get the variable value MessageBox through the string. show (this. getType (). getField ("Demo "). getValue (this ). toString (); // display the Old String // assign this to the variable. getType (). getField ("Demo "). setValue (this, "New String"); // The New Value MessageBox. show (Demo); // display New String MessageBox. show (this. getType (). getField ("Demo "). getValue (this ). toString (); // display New String}