简体   繁体   English

为什么我不能像隐藏属性一样隐藏继承的事件?

[英]Why can't I hide inherited events the same way I can hide properties?

I've got a usercontrol which inherits from the UserControl class. 我有一个继承自UserControl类的usercontrol。 There are a bunch of items I want to hide from anyone who uses the class. 我想向使用该类的任何人隐藏一些项目。

I can hide properties just fine... 我可以隐藏属性就好了......

public partial class userControls_MyControl : System.Web.UI.UserControl {

    private new bool EnableTheming {get; set;}
}

This effectively removes it from being displayed in the editor's IntelliSense. 这有效地消除了它在编辑器的IntelliSense中的显示。

However, when I try the same thing with events, they still show up... 然而,当我对事件尝试同样的事情时,他们仍然会出现......

public partial class userControls_MyControl : System.Web.UI.UserControl {

    private new EventHandler AbortTransaction { get; set; }
    private new EventHandler OnAbortTransaction {get;set;}
}

Is there any way to really hide an event? 有没有办法真正隐藏一个事件? Why isn't the above working? 为什么上述不起作用?

Thanks in advance. 提前致谢。

You are trying to hide a Property that doesn't exist. 您正试图隐藏不存在的属性。 You need to use the event syntax this would do it:- 你需要使用这样做的事件语法: -

 private new event EventHandler AbortTransaction;

You might be tempted to use the EditorBrowserable attribute and leave the event public, don't. 您可能想要使用EditorBrowserable属性并将事件公开,不要。 That could mean external code might attempt to attach to AbortTransaction on your control but that will not be seen by the inherited control code. 这可能意味着外部代码可能会尝试附加到您的控件上的AbortTransaction,但继承的控制代码将无法看到它。

尝试将EditorBrowsableAttribute(false)应用于您的事件: http//msdn.microsoft.com/en-us/library/system.componentmodel.editorbrowsableattribute.aspx

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

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