简体   繁体   English

我如何在C#中创建自定义TextBox控件

[英]How I create the custom TextBox Control in C#

I want to implement the own custom TextBox control in Asp.Net(C#). 我想在Asp.Net(C#)中实现自己的自定义TextBox控件。 Please give me some idea and links. 请给我一些想法和链接。

A control is simply a class. 控件只是一个类。 Create your own class deriving from the TextBox class. 创建派生自TextBox类的类。 Override methods. 覆盖方法。 Handle events. 处理事件。 Add properties. 添加属性。

And then ask a specific question, and you'll get specific answers. 然后提出一个特定的问题,您将得到特定的答案。 Do a search on this site and you'll find recommendations for books on control development. 在此站点上进行搜索,您将找到有关控件开发的书籍的建议。

You'll also find http://asp.net to be of use. 您还会发现http://asp.net可以使用。

If you want to create a TextBox control from scratch, you can just create a CustomControl (msdn: http://msdn.microsoft.com/en-us/library/zt27tfhy.aspx ) that outputs a textbox: 如果要从头开始创建TextBox控件,则可以仅创建一个输出文本框的CustomControl(msdn: http : //msdn.microsoft.com/zh-cn/library/zt27tfhy.aspx ):

<input type="text" />

Obviously you'll want to add properties like length and css styles. 显然,您需要添加诸如length和css样式之类的属性。 For an existing control like a TextBox I can't really imagine why you wouldn't just inherit from TextBox to add the extra functionality you want though -- why reinvent the wheel? 对于像TextBox这样的现有控件,我无法想象为什么您不只是继承自TextBox以添加所需的额外功能-为什么要重新发明轮子呢? But if that's what you want to do... 但是,如果那是您想要的...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM