如何在控件属性上显示文本框属性? [英] How can I show textbox properties on control property?

查看:108
本文介绍了如何在控件属性上显示文本框属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我创建的MyCustomTextBoxControl.ascx类型是Web用户控件。然后我向我的控件添加一个文本框。



之后我将MyCustomTextBoxControl.ascx添加到我的页面。我选择我的控件时只显示控件属性,我在设计时查看属性窗口。我想在我的控件的属性中看到文本框属性。 (不是其中之一,全是)



我该怎么做?

谢谢



示例;

Hi Everyone,
I create MyCustomTextBoxControl.ascx that type is Web User Control. Then I add a textbox to my control.

After that i add MyCustomTextBoxControl.ascx to my page. Only shows control properties when i select my control and i look at the properties windows in designing time. I want to seeing textbox properties inside of the my control''s property. (not one of them, all of them)

How can i do this?
Thanks

Example;

public partial class MyCustomTextboxControl : System.Web.UI.UserControl
 {
     [Browsable(true)]
     public TextBox MyTextBox
     {
         get
         {
             return TextBox1;
         }
         set
         {
             TextBox1 = value;
         }
     }
 }





但这是无效代码。



But this is invalid code.

推荐答案

你为什么这样做?

为什么不直接从TextBox派生 - 这样你就可以获得作为控件一部分显示的文本框的属性。

除非你在控件的上下文中添加其他控件,这是最简单的解决方案。



你真的,真的,不应该'不会以您建议的方式暴露您的内部控件 - 它会将您的控件设计锁定为包含文本框 - 您无法在不考虑其对可能使用您控件的任何内容的影响的情况下进行更改。只展示你需要的东西 - 不要暴露整个控件。
Why are you doing that?
Why not derive from a TextBox directly - that way you get the properties of the textbox shown as part of your control.
Unless you are adding other controls within the context of your control, that is the simplest solution.

And you really, really, shouldn''t expose your internal controls in the way you suggest - it locks the design of your control to containing a textbox - you can''t make changes without considering their affect on anything that might use your control. Expose only what you need to - don''t expose whole controls.


这篇关于如何在控件属性上显示文本框属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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