我应该对TextBox进行子类化吗? [英] Should I Subclass TextBox ?

查看:70
本文介绍了我应该对TextBox进行子类化吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要的文本框只允许某些类型的数据。比如

只有整数,小数等等。


为每种类型子类化TextBox或仅创建一个

更好新的TextBox类有一个属性或方法使它起作用

approprietly?


制作多个对象似乎更容易在设计中使用

时间,但我不知道如果有这么多可以合并的b $ b类是否效率低。

解决方案

嗨Phill,


你的子类是什么意思?你的意思是''继承''或者你的意思是

以旧的API方式继承子类?


如果你的意思是继承我不是它的东西在设计时使用文本框更容易

。除非你不提供自己的设计师,否则你不能使用视觉设计师。


无论如何。过滤键击的.NET方法是处理KeyPress事件。你可以创建自定义控件来托管一个编辑框并在那里进行过滤。

然后你可以添加一些属性来自定义用户控件的键击

过滤器。这是使用视觉设计师的最简单方法

-

HTH

Stoitcho Goutsev(100)[C#MVP]

" Phill" < WA ******** @ yahoo.com>在消息中写道

新闻:ac ************************* @ posting.google.co m ... < blockquote class =post_quotes>我想要的文本框只允许某些类型的数据。像
只有整数,小数等。

为每种类型子类化TextBox或仅创建一个具有属性或方法的新TextBox类更好吗? approprietly?

制作多个物品似乎在设计时更容易使用,但我不知道它是否有点效率低下这么多可以合并的课程。



你好Rachel,


如果你继承自TextBox控件,然后每当你在表单上放置

派生控件时


有捕获。你不能把它放在表格中。你只能动态地创建它b / b $ b,这意味着它不会在设计时出现。除非。正如我所说,

你不做你自己的设计师。

此外,你添加了一个特殊的属性(也许是FormatString),
它是一个基本的东西,如字符串,你可以在使用控件时从可视化设计器编辑
属性,而无需添加任何设计器代码。




完全正确,如果你可以(但你不能)把它放在表格上。

-


Stoitcho Goutsev( 100)[C#MVP]


Phill< wa ******** @ yahoo.com>写道:

我想要的文本框只允许某些类型的数据。喜欢
只有整数,小数等等。




你看过System.Windows.Forms.NumericUpDown吗?


I''d like to have textboxes that only allow certain types of data. Like
only integers, decimals, etc.

Is it better to subclass TextBox for each type or to create only one
new TextBox class that has a property or method that makes it act
approprietly?

Making multiple objects seems like it would be easier to use at design
time but I don''t know if it''s kind of inefficient to have so many
classes that could be combined.

解决方案

Hi Phill,

What do you mean by subclassing? Do you mean ''inheriting'' or you do mean
subclassing in the old API fashion?

If you mean inheriting I don''t thing it would make using the text box easier
during design time. Unless you don''t provide your own designer you cannot
use the visual designer.

Anyways. the .NET way to filter keystrokes is to handle KeyPress event. You
can create custom control that host an edit box and do the filtering there.
Then you can add some properties to customize that user control''s keystroke
filter. This is the easiest way to use the visual designer
--
HTH
Stoitcho Goutsev (100) [C# MVP]
"Phill" <wa********@yahoo.com> wrote in message
news:ac*************************@posting.google.co m...

I''d like to have textboxes that only allow certain types of data. Like
only integers, decimals, etc.

Is it better to subclass TextBox for each type or to create only one
new TextBox class that has a property or method that makes it act
approprietly?

Making multiple objects seems like it would be easier to use at design
time but I don''t know if it''s kind of inefficient to have so many
classes that could be combined.



Hi Rachel,

If you inherit from the TextBox control, then whenever you place

the derived control on a form
There is the catch. You can not place it in the form. You can only create it
dynamically, which means it won''t appear at design time. Unless. as I said,
you don''t do your own designer.
Furthermore, it you add a special property (maybe something FormatString),
and it is something basic like a string, you will be able to edit that
property from the visual designer when using the control, without having
to add any designer code.



Completely correct if you could (but you can''t) put it on the form.
--

Stoitcho Goutsev (100) [C# MVP]


Phill <wa********@yahoo.com> wrote:

I''d like to have textboxes that only allow certain types of data. Like
only integers, decimals, etc.



Have you looked at System.Windows.Forms.NumericUpDown?


这篇关于我应该对TextBox进行子类化吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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