使用Invoke调用属性 [英] Calling properties using Invoke

查看:101
本文介绍了使用Invoke调用属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我希望使用System.ComponentModel.ISynchronizeInvoke.Invoke设置/获取属性,但我找不到确切的语法..


任何线索如何做到这一点

(现在我想制作/设置Form.Enabled属性时我正在制作GetEnabled / SetEnabled方法。


感谢

JPRoo

Hi

I wish to set/get a property using System.ComponentModel.ISynchronizeInvoke.Invoke but I cannot find the exact syntax..

Any clue how to do this
(right now I am making GetEnabled/SetEnabled methods when I wish to get/set Form.Enabled property.

Thank
JPRoo

推荐答案






ISynchronizeInvoke.Invoke为您提供了一种从

不同线程调用方法的方法,以便将调用编组到正确的线程。

使用这个方法,你需要为你的调用方法创建一个委托。

有关更多信息,有一篇文章谈到这个:
http://www.fawcette.com/vsm/2003_02/...efault_pf.aspx


希望这会有所帮助,


祝你好运,

Jeffrey Tan

Microsoft在线合作伙伴支持

安全! - www.microsoft.com/security

此帖子按原样提供没有保证,也没有授予任何权利。


Hi,

ISynchronizeInvoke.Invoke gives you a way of calling a method from a
different thread to marshal the call to the proper thread.
To use this method, you need create a delegate for your calling method.
For more information, there is an article talks about this:
http://www.fawcette.com/vsm/2003_02/...efault_pf.aspx

Hope this helps,

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.


感谢您的快速回复,


我的问题是我怎么能使用Invoke获取/设置属性?

我已经使用Invoke with methods,但我找不到获取/设置属性的语法...


有可能吗?


例如:我想用myForm.Invoke设置''True''属性''myForm.Enable'',怎么做我这样做了吗?


谢谢

JPRoot

----- \Jeffrey Tan [MSFT] \ "写道:-----




ISynchronizeInvoke.Invoke为您提供了一种从

调用方法的方法不同的线程来编组调用正确的线程。

要使用这种方法,你需要为你的调用方法创建一个委托。

欲了解更多信息,有一篇文章谈到这个:
http: //www.fawcette.com/vsm/2003_02/...efault_pf.aspx

希望这会有所帮助,


此致,

Jeffrey Tan

Microsoft在线合作伙伴支持

安全! - www.microsoft.com/security

此帖子按原样提供没有保证并且没有权利。
Thanks for quick reply,

My question was how can I get/set a property using Invoke?

I already use Invoke with methods, but I haven''t found the syntax to get/set properties...

Is it possible?

Ex: I would to set to ''True'' the property ''myForm.Enable'' with myForm.Invoke, how do I do it?

Thanks
JPRoot
----- \"Jeffrey Tan[MSFT]\" wrote: -----
Hi,

ISynchronizeInvoke.Invoke gives you a way of calling a method from a
different thread to marshal the call to the proper thread.
To use this method, you need create a delegate for your calling method.
For more information, there is an article talks about this:
http://www.fawcette.com/vsm/2003_02/...efault_pf.aspx

Hope this helps,

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.


我不确定ISynchronizeInvoke为你做了什么,但是你可以获得/设置

属性使用反射,如果你想要做的那样。


假设你的Form对象名为form1,你可以做以下事情:


public void SetFormEnabled(bool enabled)

{

System.Reflection.PropertyInfo pInfo =

form1.GetType()。GetProperty(" ;已启用);

pInfo.SetValue(form1,enabled,null);

}

JPRoot< jp **** @ hotmail.com>在消息新闻中写道:< C6 ********************************** @ microso ft.com> .. 。
I''m not sure what ISynchronizeInvoke does for you, but you can get/set
properties using reflection if that''s all you want to do.

Say you have your Form object named form1, you can do the following:

public void SetFormEnabled( bool enabled )
{
System.Reflection.PropertyInfo pInfo =
form1.GetType().GetProperty("Enabled");
pInfo.SetValue( form1, enabled, null );
}
JPRoot <jp****@hotmail.com> wrote in message news:<C6**********************************@microso ft.com>...


我希望使用System.ComponentModel.ISynchronizeInvoke.Invoke设置/获取属性,但我找不到确切的语法...

任何线索如何做到这一点?
(我现在正在制作GetEnabled / SetEnabled方法,希望得到/设置Form.Enabled属性。)

谢谢
JPRoot
Hi,

I wish to set/get a property using System.ComponentModel.ISynchronizeInvoke.Invoke but I cannot find the exact syntax...

Any clue how to do this?
(right now I am making GetEnabled/SetEnabled methods when I wish to get/set Form.Enabled property.)

Thanks
JPRoot



这篇关于使用Invoke调用属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆