zoukankan      html  css  js  c++  java
  • 线程间操作控件

    
    delegate void bindvalue(object Instance, string Property, object value);
    delegate object invokemethod(object Instance, string Method, object[] parameters);
    delegate object invokepmethod(object Instance, string Property, string Method, object[] parameters);
    delegate object invokechailmethod(object InstanceInvokeRequired, object Instance, string Method, object[] parameters);

    /// <summary>
    /// 委托设置对象属性
    /// </summary>
    /// <param name="Instance">对象</param>
    /// <param name="Property">属性名</param>
    /// <param name="value">属性值</param>
    private void SetValue(object Instance, string Property, object value)
    {
    if ((bool)GetPropertyValue(Instance, "InvokeRequired"))
    {
    bindvalue d
    = new bindvalue(SetValue);
    this.Invoke(d, new object[] { Instance, Property, value });
    }
    else
    {
    SetPropertyValue(Instance, Property, value);
    }
    }
    /// <summary>
    /// 委托执行实例的方法
    /// </summary>
    /// <param name="Instance">类实例</param>
    /// <param name="Method">方法名</param>
    /// <param name="parameters">参数列表</param>
    /// <returns>返回值</returns>
    private object InvokeMethod(object Instance, string Method, object[] parameters)
    {
    if ((bool)GetPropertyValue(Instance, "InvokeRequired"))
    {
    invokemethod d
    = new invokemethod(InvokeMethod);
    return this.Invoke(d, new object[] { Instance, Method, parameters });
    }
    else
    {
    return MethodInvoke(Instance, Method, parameters);
    }
    }
    /// <summary>
    /// 委托执行实例的方法
    /// </summary>
    /// <param name="InstanceInvokeRequired">窗体控件对象</param>
    /// <param name="Instance">需要执行方法的对象</param>
    /// <param name="Method">方法名</param>
    /// <param name="parameters">参数列表</param>
    /// <returns>返回值</returns>
    private object InvokeChailMethod(object InstanceInvokeRequired, object Instance, string Method, object[] parameters)
    {
    if ((bool)GetPropertyValue(InstanceInvokeRequired, "InvokeRequired"))
    {
    invokechailmethod d
    = new invokechailmethod(InvokeChailMethod);
    return this.Invoke(d, new object[] { InstanceInvokeRequired, Instance, Method, parameters });
    }
    else
    {
    return MethodInvoke(Instance, Method, parameters);
    }
    }
    /// <summary>
    /// 委托执行实例的属性的方法
    /// </summary>
    /// <param name="Instance">类实例</param>
    /// <param name="Property">属性名</param>
    /// <param name="Method">方法名</param>
    /// <param name="parameters">参数列表</param>
    /// <returns>返回值</returns>
    private object InvokePMethod(object Instance, string Property, string Method, object[] parameters)
    {
    if ((bool)GetPropertyValue(Instance, "InvokeRequired"))
    {
    invokepmethod d
    = new invokepmethod(InvokePMethod);
    return this.Invoke(d, new object[] { Instance, Property, Method, parameters });
    }
    else
    {
    return MethodInvoke(GetPropertyValue(Instance, Property), Method, parameters);
    }
    }
    /// <summary>
    /// 获取实例的属性值
    /// </summary>
    /// <param name="ClassInstance">类实例</param>
    /// <param name="PropertyName">属性名</param>
    /// <returns>属性值</returns>
    private static object GetPropertyValue(object ClassInstance, string PropertyName)
    {
    Type myType
    = ClassInstance.GetType();
    PropertyInfo myPropertyInfo
    = myType.GetProperty(PropertyName, BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
    return myPropertyInfo.GetValue(ClassInstance, null);
    }
    /// <summary>
    /// 设置实例的属性值
    /// </summary>
    /// <param name="ClassInstance">类实例</param>
    /// <param name="PropertyName">属性名</param>
    private static void SetPropertyValue(object ClassInstance, string PropertyName, object PropertyValue)
    {
    Type myType
    = ClassInstance.GetType();
    PropertyInfo myPropertyInfo
    = myType.GetProperty(PropertyName, BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
    myPropertyInfo.SetValue(ClassInstance, PropertyValue,
    null);
    }

    /// <summary>
    /// 执行实例的方法
    /// </summary>
    /// <param name="ClassInstance">类实例</param>
    /// <param name="MethodName">方法名</param>
    /// <param name="parameters">参数列表</param>
    /// <returns>返回值</returns>
    private static object MethodInvoke(object ClassInstance, string MethodName, object[] parameters)
    {
    if (parameters == null)
    {
    parameters
    = new object[0];
    }
    Type myType
    = ClassInstance.GetType();
    Type[] types
    = new Type[parameters.Length];
    for (int i = 0; i < parameters.Length; ++i)
    {
    types[i]
    = parameters[i].GetType();
    }
    MethodInfo myMethodInfo
    = myType.GetMethod(MethodName, types);
    return myMethodInfo.Invoke(ClassInstance, parameters);
    }
  • 相关阅读:
    伟景行 citymaker 从入门到精通(2)——工程图层树加载
    伟景行 citymaker 从入门到精通系列
    伟景行 citymaker 从入门到精通(1)——js开发,最基本demo,加载cep工程文件
    Android手机屏幕投射到电脑神器Vysor
    GeoTools坐标转换(投影转换和仿射变换)
    微信开发系列(1):企业号回调模式认证
    通过扩大IE使用内存,解决skyline在IE下模型不能加载的方法
    SDE ST_Geometry SQL st_intersects查询很慢的解决方法
    axTE3DWindowEx双屏对比控件白屏解决方法以及网上方法的校正(CreateControlOveride)
    namespace使用方法
  • 原文地址:https://www.cnblogs.com/lscy/p/1986022.html
Copyright © 2011-2022 走看看