日期:2014-05-17  浏览次数:20837 次

通过反射设置其它进程窗口的属性和调用方法无效。
本帖最后由 fanyufanyu 于 2013-11-14 17:20:42 编辑
获取其它进程的属性值,可以得到。 
Pvalue=TF.Reflection_Get_Property(@"..\..\..\WindowsFormsUI\bin\Release\" + filemainname + ".exe", "WindowsFormsUI.Form4", "Text", null);
  
 public Object Reflection_Get_Property(string Path, string NameSpaceAndClassName, string PropertyName,object[] index)
        {

            Assembly Ass = Assembly.LoadFrom(Path);
            Type TP = Ass.GetType(NameSpaceAndClassName);
            PropertyInfo PI = TP.GetProperty(PropertyName);
            object MeObj = System.Activator.CreateInstance(TP);
            return PI.GetValue(MeObj, index);
            
        }
类似的代码但设置值无效。
TF.Reflection_Set_Property(@"..\..\..\WindowsFormsUI\bin\Release\" + filemainname + ".exe", "WindowsFormsUI.Form4", "Text", "Form(4)", null);

 public int Reflection_Set_Property(string Path, string NameSpaceAndClassName, string PropertyName, object value,object [] index)
        {

            Assembly Ass = Assembly.LoadFrom(Path);
            Type TP = Ass.GetType(NameSpaceAndClassName);
            PropertyInfo PI = TP.GetProperty(PropertyName);
            object MeObj = System.Activator.CreateInstance(TP);
            PI.SetValue(MeObj, value, index);
            return 0;
        }
反射调用其它窗口的方法,执行了但窗口没有效果。
TF.Reflection_Call_Method(@"..\..\..\WindowsFormsUI\bin\Release\" + filemainname + ".exe", "WindowsFormsUI.Form4", "TestAdd2", new object[]{100,30});

 public int Reflection_Call_Method(string Path, string NameSpaceAndClassName, string MethodName, object[] Parameters)
        {

            Assembly Ass = Assembly.LoadFrom(Path);
            Type TP = Ass.GetType(NameSpaceAndClassName);
            MethodInfo MI = TP.GetMethod(MethodName); 
            object MeObj = System.Activator.CreateInstance(TP);
            MI.Invoke(MeObj, Parameters);
            return 0;
        }

被反射调用的代码<