在 C#.net 上扩展复选框控件
我想扩展可以在每个表单上使用的复选框控件。
如果选中复选框,则返回“Y”,否则返回“N”。
我如何扩展复选框控件并以其他形式使用它?
I want to extend checkbox control which can use on every form.
If check box is checked than it will return "Y" otherwise "N".
How may i extend check box control and use it in other forms ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
扩展方法既快速又简单,但正如您在标签中提到的那样,您不能在 .NET 2.0 中做到这一点。
您必须创建一个新的用户控件,并在其上放置一个
CheckBox
。然后,您必须对最常见的事情做出响应,以使其像
CheckBox
一样工作。例如,您必须处理控件的
Resize()
事件,并将所做的任何更改相应地应用到其中的CheckBox
。完成所有这些操作后,您现在就拥有了一个由您自己创建的功能齐全的
CheckBox
控件,该控件非常模仿原始控件。只有这样你才能像这样创建一个公共获取属性:
就是这样。
但如果我是你,我就不会经历这些麻烦。
我会在写入数据库之前检查自己。
老实说,为这样一个微小的功能扩展现有的用户控件是不值得的。
Extension method is quick and easy, but you can't do that in .NET 2.0, as you mentioned in your tags.
You would have to create a new user control, and place a
CheckBox
on it.You would then have to respond to the most common things to make it act like a
CheckBox
.For example, you would have to handle your control's
Resize()
event, and apply whatever change made accordingly to theCheckBox
within.After all that is done, you now have a fully-functional
CheckBox
control of your own creation that very much mimics that of the original one.Only then you can create a public get property like so:
And that is it.
But if I were you, I wouldn't go through all that hassle.
I would just do that check myself right before I write to the database.
Extending an existing user control for such a minute feature is not worth it, honestly.