class ControlHelper
    {
        public static void ShowOnTxtLbl<T>(T control, string mess)
             where T : System.Windows.Forms.Control, new()
        {
            if (control.InvokeRequired)
            {
                control.BeginInvoke(new MethodInvoker(delegate
                {
                  control.Text = mess;
                }));
            }
            else
            {
                control.Text = mess;
            }
        }
    }

由于担心i别的比如datagridview控件 赋值属性与textbox和label 不同,在此方法中做判断担心影响效率,顾打算分开写。

上边的方式,两者兼容赋值。还能防止提示UI线程冲突。感觉还不错

posted on 2016-12-28 11:20  小石头的一天  阅读(210)  评论(0编辑  收藏  举报