Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 163105
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T11:30:32+00:00 2026-05-11T11:30:32+00:00

I am creating a subclass of Button and would like to add custom functionality

  • 0

I am creating a subclass of Button and would like to add custom functionality to some of its events such as OnClick. Which is the more desirable way to do it? Do I override OnClick:

protected override void OnClick(EventArgs e) {     base.OnClick(e);     doStuff(); } 

or should I instead link up the OnClick event to an event handler defined in my Button subclass through the designer?

class ButtonSubclass {     public ButtonSubclass() : base()     {         InitializeComponent();     }      private void InitializeComponent()     {         this.Click += new System.EventHandler(this.ButtonSubclass_Click);     } } 

Edit: I added minor visual changes (that may pass as rudimentary skinning) but most of the changes are in event handlers that I don’t want to re-implement (copy-paste) on every form that reuses it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T11:30:33+00:00Added an answer on May 11, 2026 at 11:30 am

    If you’re genuinely specializing the button, it makes sense to override OnClick. If you’re only actually changing what happens when a button is clicked, I wouldn’t subclass Button in the first place – I’d just add event handlers.

    EDIT: Just to give a bit more of an idea – if you want to add similar event handlers for multiple buttons, it’s easy enough to write a utility method to do that, and call it from multiple places. It doesn’t require actual subclassing. That’s not to say subclass is definitely wrong in your case, of course – just giving you extra options 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 88k
  • Answers 88k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer raise ValueError('invalid gender %r' % gender) May 11, 2026 at 5:46 pm
  • Editorial Team
    Editorial Team added an answer If you need only Dependency Injection probably AutoFac will be… May 11, 2026 at 5:46 pm
  • Editorial Team
    Editorial Team added an answer I just experienced a somewhat similar experience with setting Notepad++… May 11, 2026 at 5:46 pm

Related Questions

Okay, this is a bit abstract, but here goes: I'm creating a website and
I a modeling a system to evaluate expressions. Now the operands in these expressions
I recently had a problem in my app where some of the subviews I
I just wanted to see if I could have your thoughts on the design

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.