隐藏自现有窗体的控件派生的自定义控件中的某些事件 [英] To hide some events from Custom Control derived from existing Form's controls

查看:54
本文介绍了隐藏自现有窗体的控件派生的自定义控件中的某些事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在c#.net(4.0)中创建了Windows控件类库,其中包括一些从Windows窗体的控件派生的自定义控件.
我有一个问题,我需要隐藏一些事件,这些事件在开发人员在实际应用程序中使用它们时不应被开发人员看到.
例如控件是从TextBox控件派生的
我想从此控件中隐藏KeyPress,MultilineChanged事件,以便程序员在使用它们时(在设计时或在编码时)都无法访问它们.
所以,请让我知道该怎么做?
谢谢...

I have created Windows control class library in c#.net (4.0) which includes some custom controls derived from Windows form''s controls.
I have an issue I need to hide some events those should not be seen by developer while using them in an actual application.
e.g. a control is derived from TextBox control
I want to hide KeyPress, MultilineChanged events from this control so that those would not be accessible to the programmer while using them (neither at design time nor at coding time).
So please let me know how to do this?
Thanks...

推荐答案

我记得曾经看到过一个情况,guuy创建了一个只暴露基本控件中某些方法和属性的接口,然后创建了一个新的自定义从基本控件及其新界面派生的控件.它得到了设计人员的支持,新的customn控件仅公开了在他的界面中定义的内容.

Google是您的朋友.
I remember seeing something once where a guuy created an interface that exposed only certain methods and properties from the base control, and then createed a new custom control derived from the base control AND his new interface. It had designer support, and the new customn control only exposed the stuff (re)defined in his interface.

Google is your friend.


覆盖您要在自定义控件中隐藏的属性/事件.

[System.ComponentModel.Browsable(false)]属性装饰它们.它们不会再出现在PropertyGrid中.
Override the properties / events you want to hide in your custom control.

Decorate them with the [System.ComponentModel.Browsable(false)] attribute. They won''t appear in a PropertyGrid any more.


感谢所有我得到的解决方案

使用属性
[可浏览(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
Thanks all I have got the solution

use attributes
[Browsable(false)]


这篇关于隐藏自现有窗体的控件派生的自定义控件中的某些事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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