反射... [英] Reflection...

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

问题描述

如何编写一行代码,将对象设置为父窗体上包含的对象




基本上,我有一个usercontrol,其中我添加的可以在设计时输入的一个属性是一个对象名称(在windows上

表格)。


我希望能够在控件中为该对象设置一个变量,这样我就可以操作它了。


我知道这涉及反思,但我找不到正确的sytnax。


希望有人可以提供帮助。


提前致谢

Simon

How can I write a line of code that sets an object to be an object thats
contained on the parent form.

Basically, I have a usercontrol, where one of the properties that I have
added that can be entered at design time is an object name (on a windows
form).

I want to be able to set a variable to that object within the control so I
can then manipulate it.

I know this involves reflection, but I can''t work out the correct sytnax.

Hope somebody can help.

Thanks in advance
Simon

推荐答案

您好Simon,


您的DataObjects属于表格的ControlCollection在

DesignTime(或ComponentTray)或者是否在运行时被亵渎。

我想这篇文章与我回复的其他帖子有关到。


如果你能把你的班级和我邮寄给我生病了。如果我的Gut

感受是的,我想我知道如何解决你的问题。


如果你想把你的课邮寄给我,请告诉我,然后我会给你我的

电子邮件地址。


亲切的问候,


Michael

" Simon Verona" <是ne ** @ aphroditeuk.com>在消息中写道

新闻:OP ************** @ tk2msftngp13.phx.gbl ...
Hi Simon,

Do your DataObjects belong to the ControlCollection of the Form at
DesignTime (or ComponentTray) or are they Instanciated at Run-Time.
I guess this post is related to the other I''ve replied to.

If you wich you can mail me your Class and I will look into it. If my "Gut
feelings" are right, I think I know how to resolve your problem.

Just let me know if you want to mail me your class, then I''ll give you my
email-address.

Kind regards,

Michael
"Simon Verona" <ne**@aphroditeuk.com> wrote in message
news:OP**************@tk2msftngp13.phx.gbl...
我怎么写一个将对象设置为父窗体上包含的对象的代码行。

基本上,我有一个usercontrol,其中添加了一个属性
可以在设计时输入的是一个对象名称(在windows
表单上)。

我希望能够在控件中为该对象设置一个变量,所以我然后可以操纵它。

我知道这涉及到反思,但我找不到正确的sytnax。

希望有人可以提供帮助。

提前致谢
Simon
How can I write a line of code that sets an object to be an object thats
contained on the parent form.

Basically, I have a usercontrol, where one of the properties that I have
added that can be entered at design time is an object name (on a windows
form).

I want to be able to set a variable to that object within the control so I
can then manipulate it.

I know this involves reflection, but I can''t work out the correct sytnax.

Hope somebody can help.

Thanks in advance
Simon



Michael


课程是非常简单..这是一个简单的类,不是从任何东西继承




类的实例在Windows窗体中定义为一个表单等级

对象......


ie朋友myObject作为新的myClass

public sub new()... etc etc etc


你说的是正确的,这与我的其他帖子有关..我继承的文本框

将属性设置为myObject。 (在上面的例子中)...我只是想要获得对myObject的访问权限,以便我可以在

bindings.add(" text", this_is_the_function_I_Need(" M yObject")," MyProperty")

声明类型....


我还没试过任何一个你的想法......但我会!无论如何,我认为我还需要解决这个问题..


非常感谢


西蒙

" Michael Maes" < MI ***** @ merlot.com>在消息中写道

news:em ************** @ TK2MSFTNGP10.phx.gbl ...
Michael

The class is pretty straightforward.. It''s a simple class, not inherited
from anything.

The instance of the class is defined within the Windows form as a form level
object...

ie Friend myObject as new myClass
public sub new() ... etc etc etc

You are correct it''s related to my other post.. my inherited text box
will have a property set to "myObject" (in the above example) ... I simply
want to gain access to myObject so that I can use it in a
bindings.add("text",this_is_the_function_I_Need("M yObject"),"MyProperty")
type of statement....

I''ve not yet tried any of your ideas yet... but I will be! In any case, I
think I still need to solve this issue..

Many thanks

Simon
"Michael Maes" <mi*****@merlot.com> wrote in message
news:em**************@TK2MSFTNGP10.phx.gbl...
嗨Simon,

您的DataObjects是否属于
DesignTime(或ComponentTray)的Form的ControlCollection,或者它们是否在运行时处于Instanciated状态。
我想这篇文章与另一篇文章有​​关I'已经回复了。

如果你能把你的课程邮寄给我,我会调查它。如果我的Gut
感情是的,我想我知道如何解决你的问题。

如果你想把你的课程邮寄给我,请告诉我,然后我会给你我的
电子邮件地址。

亲切的问候,

Michael

" Simon Verona" <是ne ** @ aphroditeuk.com>在消息中写道
新闻:OP ************** @ tk2msftngp13.phx.gbl ...
Hi Simon,

Do your DataObjects belong to the ControlCollection of the Form at
DesignTime (or ComponentTray) or are they Instanciated at Run-Time.
I guess this post is related to the other I''ve replied to.

If you wich you can mail me your Class and I will look into it. If my "Gut
feelings" are right, I think I know how to resolve your problem.

Just let me know if you want to mail me your class, then I''ll give you my
email-address.

Kind regards,

Michael
"Simon Verona" <ne**@aphroditeuk.com> wrote in message
news:OP**************@tk2msftngp13.phx.gbl...
如何编写一行代码将一个对象设置为父窗体上包含的对象。

基本上,我有一个usercontrol,其中添加了一个可以输入的属性在设计时是一个对象名称(在窗口
窗体上)。

我希望能够在控件中为该对象设置一个变量,所以
然后我可以操作它。

我知道这涉及反思,但我无法找到正确的
sytnax。
希望有人可以提供帮助。

谢谢提前
Simon
How can I write a line of code that sets an object to be an object thats
contained on the parent form.

Basically, I have a usercontrol, where one of the properties that I have
added that can be entered at design time is an object name (on a windows
form).

I want to be able to set a variable to that object within the control so I can then manipulate it.

I know this involves reflection, but I can''t work out the correct sytnax.
Hope somebody can help.

Thanks in advance
Simon




早上好Simon,


我想我现在对你的问题有了更好的了解(有点晚了......)。


所以要确定:


你的DataObject是通过Code实现的,例如:

Friend MyDataOb ject As DataObjectClass_A

Private Sub Form1_Load(ByVal sender As System.Object,ByVal e As System.EventArgs)Handles MyBase.Load


MyDataObject = New DataObjectClass_A

MyTextBox.DataBindings.Add(New System.Windows.Forms.Binding(" Text",MyDataObject," Property_XYZ"))

>
End Sub


我怀疑是这种情况,因为那会有点简单.....


您的DataObjectClass是一个组件吗? (您将工具箱中的DataObject添加到ComponentTray,就像使用DataSet一样)


公共类DataObjectClass


继承System.ComponentModel .Component


.............

结束班级


如果两个场景都不适用于您的情况,那么请您明确说明您的DataObjects如何实现(例如:远程处理,WebService,......)


反射可以在运行时和运动时使用。 DesignTime,但我还不确定你是否需要它。我想我可以在这里帮助你,但如果你发布(或邮寄)我一些(虚拟)代码(保留层次结构,命名空间等等),这将是非常有用的。


祝你好运,


Michael

Good morning Simon,

I think I''m getting a better idea of your issue now (a bit late hum...).

So to be sure:

Is your DataObject instanciated through Code, something like:
Friend MyDataObject As DataObjectClass_A

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

MyDataObject = New DataObjectClass_A

MyTextBox.DataBindings.Add(New System.Windows.Forms.Binding("Text", MyDataObject, "Property_XYZ"))

End Sub

I doubt this is the case, because that would be a bit simple.....

Is your DataObjectClass a Component? (You add a DataObject from the Toolbox to your ComponentTray like you would do with a DataSet)

Public Class DataObjectClass

Inherits System.ComponentModel.Component

.............

End Class

If both scenario''s don''t apply to your case, then could you please make clear How your DataObjects get instanciated (eg: Remoting, WebService, ....)

Reflection can be used both at Runtime & DesignTime, but I''m not yet convinced you need it. I think I can help you out here, but it would be verry helpful if you posted (or mailed) me some (dummy)-code (keeping the Hierarchy, Namespaces, etc...)

Best regards,

Michael


这篇关于反射...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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