自定义构造函数或属性 [英] Custom Constructors or Properties

查看:154
本文介绍了自定义构造函数或属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,

我知道我以前做过这件事,或者说非常相似的事情,但我不能为我的生活记住这一点。 我确信它使用Designer,TypeConverter或Serializer:

I know I've done this before, or something very similar but I cannot for the life of me remember how.  I am sure it uses a Designer, TypeConverter, or Serializer:

//From1.Designer.cs

private void InitializeComponents() 
{
   this.myUserControl1 = new MyUserControl(this);  

   /// OR

   // 
   // myUserControl1
   //
   this.myUserControl1.MyParentControl = this;

}


基本上,我想添加一个用户控件,以便表单设计器将解释传递自身的自定义构造函数("this"引用)

Basically, I want to add a user control so that the Forms Designer will either interpret the custom constructor passing itself (the "this" reference)

或在控件上有一个属性,当它被放入一个对于特定类型的父控件(ContainerControl,Form或MySpecialUserControl),它将为该属性分配"this"。值得自动。

or has a property on the control that when dropped into a parent control of a specific type, (ContainerControl, Form, or MySpecialUserControl) it will assign the property the "this" value automatically.

我知道这需要Designer或Serializer等,但我不记得是什么,我也找不到这样做的原始代码。

I know this will require a Designer or Serializer or something, but I can't remember what, nor can I find my original code that did this.

谢谢

Jaeden" Sifo Dyas" al'Raec Ruiner

Jaeden "Sifo Dyas" al'Raec Ruiner

"绝不相信计算机。你的大脑比任何微芯片都聪明。"


PS - 不要在其他人的问题上标记答案。有假期和假期这样的事情可能会减少及时的活动,直到提出问题的人可以测试你的答案,这只是因为你认为它是不正确的。将它标记为
对它们的正确性通常会阻止其他人阅读问题,并可能提供真实的"正确"信息。回答。

"Never Trust a computer. Your brain is smarter than any micro-chip."
PS - Don't mark answers on other people's questions. There are such things as Vacations and Holidays which may reduce timely activity, and until the person asking the question can test your answer, it is not correct just because you think it is. Marking it correct for them often stops other people from even reading the question and possibly providing the real "correct" answer.

推荐答案

如果在设计时将控件从工具箱拖到Container控件。设计者会将控件添加到容器控件集合中,并将容器设置为控件的父级。

If you drag a control from toolbox to a Container control in the design time. the designer would add the control to the container controls collection and set the container as parent of the control.

但是父属性并不总是与"this"相同,因为" ;这"你的意思是顶级父控件..

but the parent property is not always the same as "this", because the "this" you mean is the top level parent control..


这篇关于自定义构造函数或属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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