C# 一些代码小结--UI操作

C# 一些代码小结--UI操作

使用控件名调用控件
object obj = this.GetType().GetField("控件名",
                        System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance
                        | System.Reflection.BindingFlags.IgnoreCase).GetValue(this);
ComboBox cb = (ComboBox)obj;
在控件触发事件时判断触发事件的控件
TextBox text = sender as TextBox;
int id = 0;
String str = null;
switch (text.Name)
跨线程使用委托调用UI控件
 public delegate void ShowMessage();//创建一个代理 
public void ShowTextBox(TextBox tx,String num)
 {
     if (tx.InvokeRequired)
     {
         ShowMessage msg;
         msg = () =>
         {
             tx.Text = num;
         };
         tx.Invoke(msg);
         return;
     }
     else
     {
         tx.Text = num;
     }
 }
posted @ 2019-03-22 09:39  MemoryPro  阅读(1013)  评论(0编辑  收藏  举报