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 6860345
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:23:51+00:00 2026-05-27T02:23:51+00:00

Probably this is a naive question, but I didn’t find an answer. I’m creating

  • 0

Probably this is a naive question, but I didn’t find an answer.

I’m creating an UserControl (button like for Winform). Once I have it, I’m using it as a Collection in a Container (really is another UC inherited from Control. I place this container in a form and then I create programmatically a Collection of the “buttons” like this;

tMenu.Add(new TrevoButton(Test.Properties.Resources.Mapa, "Map", "MapaClick"));
tMenu.Add(new TrevoButton(Test.Properties.Resources.Inst, "Install", "InstaClick"));
tMenu.Add(new TrevoButton(Test.Properties.Resources.Mode, "Model", "ModelClick"));

The parameters are:

  • Image (Image): image of the button
  • Text (string): text of the button
  • Event (string): name of the event to be fired when the “button” is clicked.

My question is that, given the event name, how do I do to assign it like a method for the button?

Thanks in advance.

  • 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-27T02:23:51+00:00Added an answer on May 27, 2026 at 2:23 am

    Found what I needed.

    This is the ADD to the collection (no quotation marks at the third parameter):

    tMenu.Add(new TrevoButton(Test.Properties.Resources.Mapa, "Mapa", MapaClick));
    

    In the form (same place where I add the items), I’m defining “MapaClick” as:

      public void MapaClick(object sender, EventArgs e)
      {
         MessageBox.Show("MapaClick");
      }
    

    And then, the constructor of the UserControl receives an EventHandler parameter:

      public TrevoButton(Image pImagen, string pTexto, EventHandler pEvento)
      {
         Image = pImagen;
         Texto = pTexto;
         this.Click += new EventHandler(pEvento);
         Iniciar();
      }
    

    That’s it. When I press the button, the message appears!
    Thanks to @lAbstract. Your response put me in that way.

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

Sidebar

Related Questions

This is probably a naive question but, how do I get the length of
This is probably a naive question about XmlReader , but I haven't turned up
This probably has a simple answer, but I must not have had enough coffee
This probably sounds like a terrible idea at first glance, but here is my
I could probably find this out from somewhere else but thought it would be
Ok, this probably has a really simple answer, but I've never tried to do
This is probably a very naive Emacs question - I'm new to it. When
It's probably a naive question, But I am feeling kinda lost. I read iOS
This probably comes across as a very naive question, and I am absolutely assuming
This is probably a multi-part question. Background: we have a native (c++) library that

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.