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

  • SEARCH
  • Home
  • 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 383351
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T15:16:28+00:00 2026-05-12T15:16:28+00:00

I have my own custom control derived from System.Windows.Forms.TreeView which is present on the

  • 0

I have my own custom control derived from System.Windows.Forms.TreeView which is present on the designer toolbox.

I add an instance of this custom control to my form (using the designer).

The purpose I created an inherited control is that I want to let the control itself handle its events since it’s supposed to act as a View in a standard MVC design. I.e. when the node selection in the treeview changes I want the view to handle all interactions with the Model.

The problem is that when I add an event for my custom control (using the designer), the event gets added to my MainForm class. The only option in such case is to forward every event into my custom control, which doesn’t feel very optimal.

Is there a way to control which class the event gets added to? I know it’s technically possible since I can edit the auto-generated code for my MainForm and make the event being triggered into the custom control. That’s clearly not the proper solution though.

Thanks.

  • 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. Editorial Team
    Editorial Team
    2026-05-12T15:16:28+00:00Added an answer on May 12, 2026 at 3:16 pm

    Tom Frey is right. If you want the behavior on a certain event to be handled by the class that would normally fire the event, the preferred technique is to override the appropriate method that fires the event to perform your task. The eventing infrastructure is overkill and not really designed for what you’re trying to do here.

    The reason is that you want every instance of your view to perform these actions. You don’t want these actions to be dynamically assigned and determined at runtime by things external to your view (which is what events are for).

    One important thing to include when you perform such an override, however, is the call to the base’s implementation. If you don’t, you may encounter strange errors:

    protected override void OnNodeMouseClick(TreeNodeMouseClickEventArgs e)
    {
        // Do stuff you want done before here
        base.OnNodeMouseClick(e);
        // Do stuff you want done after here
    }
    

    Calling the base class will fire the event and may perform other actions besides. If you want something done before the event fires and any external subscribers do their thing, put it before the call to the base. If you want something done after all the events have fired and been handled, put it after. Contrived example: if your control handled some data binding, then you might want to verify the databinding exists before the call to base and you might want to verify it’s valid after (in case a handler munged something).

    From MSDN:

    The OnNodeMouseClick method also
    allows derived classes to handle the
    event without attaching a delegate.
    This is the preferred technique for handling the event in a derived
    class.

    Notes to Inheritors:

    When overriding OnNodeMouseClick in
    a derived class, be sure to call the
    base class’s OnNodeMouseClick method
    so that registered delegates receive
    the event.

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

Sidebar

Related Questions

I have my own control derived from Windows.Forms.Control and I am checking the Parent.BackColor
I'm trying to derive from the Silverlight Panel control to add some custom logic
I am using a Windows Forms TreeView control in my program. I would like
I have a my own custom web server control. I created separate CSS file
I have own control implemented in CommonControls assembly (the same namespace). It us 'Custom
Most mature C++ projects seem to have an own reflection and attribute system ,
If I want to bind to properties of my custom control from Interface Builder
We have our own ORM we use here, and provide strongly typed wrappers for
I have my own game engine using C++ and OpenGL, but I have models
I have a big list of global variables that each have their own setup

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.