示例#1
0
        public static object InvokePropertyMethod(Control ctrl, string propertyName, string methodName, params object[] args)
        {
            if (ctrl.InvokeRequired)
            {
                InvokePropertyMethodDelegate del = new InvokePropertyMethodDelegate(CrossThreadUI.InvokePropertyMethod);
                if (CrossThreadUI.ExecSync)
                {
                    ctrl.Invoke(del, ctrl, propertyName, methodName, args);
                }
                else
                {
                    ctrl.BeginInvoke(del, ctrl, propertyName, methodName, args);
                }
            }
            else
            {
                object propVal = CrossThreadUI.GetPropertyInstance(ctrl, propertyName);
                if (propVal != null)
                {
                    Type objType = propVal.GetType();

                    // Determine the type of each passed argument in order to try and
                    //   determine the unique signature for the requested method.
                    Type[] paramTypes = new Type[args.Length];
                    for (int i = 0; i < paramTypes.Length; i++)
                    {
                        paramTypes[i] = args[i].GetType();
                    }

                    // Now, it's time to get a reference to the method.
                    MethodInfo mi = objType.GetMethod(methodName, paramTypes);
                    if (mi != null)
                    {
                        return(mi.Invoke(propVal, args));
                    }
                    else
                    {
                        throw new ArgumentException("Specified ('" + propertyName + "') property value does not expose a '" + methodName + "' method with the provided parameter types.");
                    }
                }
            }
            return(null);
        }
示例#2
0
 public static void SetValue(Control ctrl, object value)
 {
     try
     { CrossThreadUI.SetPropertyValue(ctrl, "Value", value); }
     catch { throw; }
 }
示例#3
0
 public static void SetChecked(Control ctrl, bool value)
 {
     try
     { CrossThreadUI.SetPropertyValue(ctrl, "Checked", value); }
     catch { throw; }
 }