hi,
what's the most convinient way of hiding events in inherited controls?
I've created my own button control which derive from
System.Windows.Forms.Control, which provides DoubleClick event. Normal
button does not need this event, what's more i have to override
OnDoubleClick to perform two normal clicks when user accidentaly double
clicks my button.
Now, i would like to hide DoubleClick event in my button because it is
never raised. for now i've just done something like this:
[EditorBrowsable(EditorBrowsableState.Advanced), Browsable(false)]
public event EventHandler DoubleClick;
Although this hides the event, but raises two compiler warnings:
CS0067: the event is never used - which is obvious
CS0108: the keyword new is required because it hides inherited member -
which is also obvious because that's my intention
i would like to know if this is a proper way of doing this things and is
it possible to somehow force the compiler not to throw these warnings on
this exact line (i don't want it to skip all of these warnings).
Ray Cassick (Home) - 16 Feb 2006 07:07 GMT
The OOP purists are going to say that if you need to hide part of the
implementation of the base control them you should not use it as a base :)
I don't agree of course and have run into the same thing myself trying to
hide unused properties.
Never did really some up with a good way to do it for sure.
> hi,
>
[quoted text clipped - 18 lines]
> it possible to somehow force the compiler not to throw these warnings on
> this exact line (i don't want it to skip all of these warnings).
SharpCoderMP - 16 Feb 2006 09:33 GMT
> The OOP purists are going to say that if you need to hide part of the
> implementation of the base control them you should not use it as a base :)
aaaahhh the OOP purists.... well the trick that i used is also used by
MS in their implementation of a System.Windows.Forms.Button control
which derives from ButtonBase, which hides the DoubleClick event of its
base class in the same manner :) maybe the purist would like to write
their own implementation of Control class without this particular
event... well if they really have to - it's their choice :D
i just wanted to know if there are some other ways of doing this. and if
not, is there some way of persuading the compiler not to throw these two
warnings i mentioned on this particular line of code.
> I don't agree of course and have run into the same thing myself trying to
> hide unused properties.
[quoted text clipped - 23 lines]
>> it possible to somehow force the compiler not to throw these warnings on
>> this exact line (i don't want it to skip all of these warnings).
Bob Powell [MVP] - 25 Feb 2006 16:34 GMT
Make your class implement ICustomTypeDescriptor and filter the events and
properties as you wish.
Your class will not actually remove the events or properties, they will
still be available through code but not to reflection ans so not to the
Property grid or for use at design time.

Signature
Bob Powell [MVP]
Visual C#, System.Drawing
Ramuseco Limited .NET consulting
http://www.ramuseco.com
Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm
Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm
All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
> hi,
>
[quoted text clipped - 18 lines]
> it possible to somehow force the compiler not to throw these warnings on
> this exact line (i don't want it to skip all of these warnings).