Get the control based on control Id and operate on it

  • 2020-12-19 20:58:33
  • OfStack

When doing dynamic fetch control, you often need to get the control according to Id and operate on it
 
/// <summary> 
///  According to the control id Get control  
/// </summary> 
/// <param name="name"></param> 
/// <returns></returns> 
private Control GetControl(string name) 
{ 
object o = this.GetType().GetField(name, System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.IgnoreCase).GetValue(this); 
return ((Control)o); 
} 

This method will quickly find the control

Related articles: