CiaranODonnell
Mon Jul 07 10:27:03 CDT 2008
You can remove an event handler in C# with a line looking almost identical to
the line that adds it (found in the designer file) but change the += to -=
--
Ciaran O''Donnell
http://wannabedeveloper.spaces.live.com
"Bob Powell [MVP]" wrote:
> There are mixed views on this subject.
>
> Looking at it from a pure architecture viewpoint I would say that if there
> is any intention that the final object will be derived from later then the
> OnXXX overrides should be used in preference to the events. If the object,
> such as a form, is known to be the final version then the events may be
> used.
>
> It is interesting to note that C# and VB design times handle these cases
> differently. C# subscribes to the event and VB adds an override which is
> more architecturally sound when you consider the implications for
> polymorphism that handling ones own events implies.
>
> The C# practice of adding an event handler is very bad because there is
> technically no way to remove these handlers should the derived class need
> to. I therefore write such handler code by hand in the case of user controls
> because I write almost exclusively in C# and I require that polymorphism
> rules are obeyed in case I need to derive from the user control at a later
> date.
>
> I cite this because really a user control, at least in it's design-time
> mode, can be considered like a form without a title bar.
>
>
>
> --
> --
> 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.
>
>
> "John A Grandy" <johnagrandy-at-gmail-dot-com> wrote in message
> news:eHYRneW1IHA.1240@TK2MSFTNGP02.phx.gbl...
> > I'm new to WinForms.
> >
> > What's the preferred way of implementing event handlers for a Form ?
> >
> > Override the protected "OnEvent" methods ... ?
> >
> > Write a custom handler and add to the event a new delegate initialized to
> > the handler ?
> >
> > Thanks.
> >
>
>