简体   繁体   中英

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. 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.

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. 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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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