Matthew Steven Kelly

Programmatically click a C# button

February10

Many times I am writing a c# application where a certain function needs to be performed on a timer event as well as from a user clicking a button. So in the effort of keeping the programmatic functionality the same as the user clicked event, we can programmatically click the button:

btnProcessData_Click(this, new EventArgs());

One could argue that it would be just as easy to to call a function from both locations such as ProcessData() instead of clicking the button programmatically, but the advantage is if a programmer in the future (or even you down the road) adds logic to the _Click event, it won’t be implemented in the triggered event (an event you or the new programmer may not remember or know occurs).

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Blogplay
posted under Random

Email will not be published

Website example

Your Comment: