[英]Why can't I hide inherited events the same way I can hide properties?
我有一個繼承自UserControl類的usercontrol。 我想向使用該類的任何人隱藏一些項目。
我可以隱藏屬性就好了......
public partial class userControls_MyControl : System.Web.UI.UserControl {
private new bool EnableTheming {get; set;}
}
這有效地消除了它在編輯器的IntelliSense中的顯示。
然而,當我對事件嘗試同樣的事情時,他們仍然會出現......
public partial class userControls_MyControl : System.Web.UI.UserControl {
private new EventHandler AbortTransaction { get; set; }
private new EventHandler OnAbortTransaction {get;set;}
}
有沒有辦法真正隱藏一個事件? 為什么上述不起作用?
提前致謝。
您正試圖隱藏不存在的屬性。 你需要使用這樣做的事件語法: -
private new event EventHandler AbortTransaction;
您可能想要使用EditorBrowserable屬性並將事件公開,不要。 這可能意味着外部代碼可能會嘗試附加到您的控件上的AbortTransaction,但繼承的控制代碼將無法看到它。
嘗試將EditorBrowsableAttribute(false)
應用於您的事件: http : //msdn.microsoft.com/en-us/library/system.componentmodel.editorbrowsableattribute.aspx
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.