using System; using System.Collections.Generic; using System.Text; using System.Windows.Forms; namespace SocketClient { /// <summary> /// 跨线程改变界面UI的工具类 CtrlHelper /// TY /// 20090820 /// </summary> public class CtrlHelper { /// <summary> /// 跨线程改变界面UI /// </summary> /// <param name="ctrl">控制对象</param> /// <param name="c">目标对象</param> /// <param name="prop">目标属性</param> /// <param name="value">值</param> public static void SetValue(Ctrl ctrl, Control c, string prop, object value) { ctrl.Control=c; ctrl.Property=prop; ctrl.Value=value; SetValue(ctrl); } private static void SetValue(Ctrl c) { if (c.Control.InvokeRequired) { Action<Ctrl> d = new Action<Ctrl>(SetValue); c.Control.Invoke(d, c); return; } c.Control.GetType().GetProperty(c.Property).SetValue(c.Control, c.Value, null); } } /// <summary> /// 控制类 /// </summary> public class Ctrl { private Control _control; private string _property; private object _value; public Control Control { get { return this._control; } set { _control = value; } } public string Property { get { return this._property; } set { _property = value; } } public object Value { get { return this._value; } set { _value = value; } } } }