C# 一些代码小结--UI操作
分享一个我个人的导航网站,小牛导航
小牛导航,爱再来一次(super-nb.com)
使用控件名调用控件
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;
}
}
更多NET精彩资源 https://super-nb.com/design
链接:https://pan.baidu.com/s/1tmlqOFOoFZdWp2uuRHNRrQ
提取码:fdeb