如何让usercontrol自动将代码添加到表单中的初始化代码中... [英] How to get a usercontrol to automatically add code to the initialization code in a form...

查看:58
本文介绍了如何让usercontrol自动将代码添加到表单中的初始化代码中...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

希望有人可以提供帮助!


当我添加自己编写的自定义控件时,我希望自动能够在Windows窗体上的初始化例程中添加代码一个表格。


具体来说,我正在尝试将数据绑定到普通类。所以我已经扩展了标准文本框以包含对象名称和属性名称的字段。我希望能够添加如下行:


controlname.DataBindings.Add(" Text",objectName," myPropertyName")

我曾尝试使用谷歌并查看文档,但似乎无法找到这个......我不知道是否有另一种方法在表单的启动代码中执行此操作(我似乎有一个想法,反射可以用于获取上面的数据绑定代码的对象的实例,但我不知道如何!!)。


我会很感激任何指示。


非常感谢提前


Simon

Hope somebody can help!

I want to automatically be able to add code to the initialize routine on a Windows form when I add a custom control that I''ve written to a form.

Specifically, I''m trying to data bind to a normal class. So I''ve extended the standard text box to include a field for object name and property name. I want to be able to add a line such as :

controlname.DataBindings.Add("Text", objectName, "myPropertyName")
I''ve tried using google and looking at the documentation but can''t seem to find this... I don''t know if there is an alternative way of doing it in the startup code of the form (I seem to have a thought that reflection could be used to get the instance of the object for the data binding code above but I can''t work out how!!).

I would be grateful for any pointers.

Many thanks in advance

Simon

推荐答案

我认为这是你正在谈论的网络形式。如果是这样,每个userconrol都有自己的Page_load事件。在这个你应该能够在父容器中绑定和对象,没有时间现在查找属性,但在psuedo我想象如果会是这样的。

Me.Parent.Control.DataBindings 。添加(文字,我,物业)


-


OHM(特里伯恩斯)

。 。 。单手人。 。


当你不知道自己在做什么时,过得很快


Simon Verona <是ne ** @ aphroditeuk.com>在留言新闻中写道:OA ************** @ TK2MSFTNGP09.phx.gbl ...

希望有人可以提供帮助!


当我添加一个我写入表单的自定义控件时,我想自动能够在Windows窗体上的初始化例程中添加代码。


具体来说,我正在尝试将数据绑定到普通类。所以我已经扩展了标准文本框以包含对象名称和属性名称的字段。我希望能够添加如下行:


controlname.DataBindings.Add(" Text",objectName," myPropertyName")

我曾尝试使用谷歌并查看文档,但似乎无法找到这个......我不知道是否有另一种方法在表单的启动代码中执行此操作(我似乎有一个想法,反射可以用于获取上面的数据绑定代码的对象的实例,但我不知道如何!!)。


我会很感激任何指示。


非常感谢提前


Simon
I assume this is a webform you are talking about. If so, each userconrol has its owen Page_load event. In this you should be able to bind and object in the parent container, dont have time to look up the properties now but in psuedo I imagine if would be something like.
Me.Parent.Control.DataBindings.Add( Text, me, Property)

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .

Time flies when you don''t know what you''re doing

"Simon Verona" <ne**@aphroditeuk.com> wrote in message news:OA**************@TK2MSFTNGP09.phx.gbl...
Hope somebody can help!

I want to automatically be able to add code to the initialize routine on a Windows form when I add a custom control that I''ve written to a form.

Specifically, I''m trying to data bind to a normal class. So I''ve extended the standard text box to include a field for object name and property name. I want to be able to add a line such as :

controlname.DataBindings.Add("Text", objectName, "myPropertyName")
I''ve tried using google and looking at the documentation but can''t seem to find this... I don''t know if there is an alternative way of doing it in the startup code of the form (I seem to have a thought that reflection could be used to get the instance of the object for the data binding code above but I can''t work out how!!).

I would be grateful for any pointers.

Many thanks in advance

Simon


特里,


不是它的Windows形式..


它上周我提到的关于数据绑定到一个简单对象的问题。哪个工作正常...除了你需要手动添加一些代码来将文本框数据绑定到主窗体中的对象...


我想要的是所以这个步骤是自动化的。


我创建了一个继承的文本框,允许我输入对象的名称和要绑定的属性。这很容易..我仍在努力使实际绑定成为自动的方法。即不需要手动添加绑定代码。因此,我希望绑定代码能够自动添加到控件初始化代码中,它设置所有控件属性。或者,一旦设置了对象和属性名称,就可以找到一些从控件本身进行绑定的方法...


这有意义吗?


问候

Simon

一手人(OHM - 特里伯恩斯) < news.microsoft.com>在消息新闻中写道:eF ************** @ TK2MSFTNGP11.phx.gbl ...

我认为这是你正在谈论的网络形式。如果是这样,每个userconrol都有自己的Page_load事件。在这个你应该能够在父容器中绑定和对象,没有时间现在查找属性,但在psuedo我想象如果会是这样的。

Me.Parent.Control.DataBindings 。添加(文字,我,物业)


-


OHM(特里伯恩斯)

。 。 。单手人。 。


当你不知道自己在做什么时,过得很快


Simon Verona <是ne ** @ aphroditeuk.com>在留言新闻中写道:OA ************** @ TK2MSFTNGP09.phx.gbl ...

希望有人可以提供帮助!


当我添加一个我写入表单的自定义控件时,我想自动能够在Windows窗体上的初始化例程中添加代码。


具体来说,我正在尝试将数据绑定到普通类。所以我已经扩展了标准文本框以包含对象名称和属性名称的字段。我希望能够添加如下行:


controlname.DataBindings.Add(" Text",objectName," myPropertyName")

我曾尝试使用谷歌并查看文档,但似乎无法找到这个......我不知道是否有另一种方法在表单的启动代码中执行此操作(我似乎有一个想法,反射可以用于获取上面的数据绑定代码的对象的实例,但我不知道如何!!)。


我会很感激任何指示。


非常感谢提前


Simon
Terry,

No it''s a Windows Form..

It refers to my question last week about data binding to a simple object. Which works fine... except that you need to manually add some code to databind the text boxes to the object in your main form...

I''m trying to get is so that somehow this step is automated.

I''ve created an inherited text box that allows me to enter the name of the object and the property to bind to. This is the easy bit.. I''m still working on some way of getting the actual binding to be "automatic" ie not require the binding code to be added manually. I''d therefore like the binding code to be added automatically in the control intialization code where it sets all the control properties.. or alternatively, find some way of doing the binding from the control itself, once the object and property names are set...

Does this make sense?

Regards
Simon
"One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote in message news:eF**************@TK2MSFTNGP11.phx.gbl...
I assume this is a webform you are talking about. If so, each userconrol has its owen Page_load event. In this you should be able to bind and object in the parent container, dont have time to look up the properties now but in psuedo I imagine if would be something like.
Me.Parent.Control.DataBindings.Add( Text, me, Property)

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .

Time flies when you don''t know what you''re doing

"Simon Verona" <ne**@aphroditeuk.com> wrote in message news:OA**************@TK2MSFTNGP09.phx.gbl...
Hope somebody can help!

I want to automatically be able to add code to the initialize routine on a Windows form when I add a custom control that I''ve written to a form.

Specifically, I''m trying to data bind to a normal class. So I''ve extended the standard text box to include a field for object name and property name. I want to be able to add a line such as :

controlname.DataBindings.Add("Text", objectName, "myPropertyName")
I''ve tried using google and looking at the documentation but can''t seem to find this... I don''t know if there is an alternative way of doing it in the startup code of the form (I seem to have a thought that reflection could be used to get the instance of the object for the data binding code above but I can''t work out how!!).

I would be grateful for any pointers.

Many thanks in advance

Simon


*One Handed Man \(OHM - Terry Burns \) < news.microsoft.com> scripsit:
* "One Handed Man \( OHM - Terry Burns \)" <news.microsoft.com> scripsit:
我认为这是你正在讨论的webform。
I assume this is a webform you are talking about.




OP提到的Windows窗体......


:-)

-

Herfried K. Wagner [MVP]

< URL:http://dotnet.mvps.org/>



The OP mentioned "Windows Form"...

:-)

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>


这篇关于如何让usercontrol自动将代码添加到表单中的初始化代码中...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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