C# Event Accessors#

I'm working on a project where a customer needs some custom controls.  One of the requirements is to have a UserControl contain a TextBox and a Button and to expose an event that will be raised when the button is clicked.  Easy enough, but to enhance the design time experience instead of adding a ButtonClick event for example, I added the following to the UserControl

public new event EventHandler Click
{
   add
   {
      lock (m_button)
      {
         m_button.Click +=
value;
      }
   }
   remove
   {
      lock (m_button)
      {
         m_button.Click -=
value;
      }
   }
}

What this does is instead of adding the EventHandler to the UserControl.Click event, I add it straight to the m_button.Click event.  Not terribly complicated but gives a better design time experience and avoids creating a new event to expose.

For more info on declaring events see here.


C#
Thursday, November 23, 2006 9:37:07 AM (Eastern Standard Time, UTC-05:00) #    Comments [1]  | 

 

All content © 2008, Mark Arteaga
On this page
Related Sites
Archives
Sitemap
Disclaimer

Powered by: newtelligence dasBlog 1.9.7174.0

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

Send mail to the author(s) E-mail

Theme design by Jelle Druyts