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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:50:07+00:00 2026-05-26T15:50:07+00:00

I have 2 buttons. I am trying to use event from button 1 into

  • 0

I have 2 buttons. I am trying to use event from button 1 into button 2 so they both do the same thing.
So by clicking 2, button 1 get clicked also. I am doing this actually from menu strip item but I suppose it has the same principle. I just don’t want to have duplicated code. I thought that button1.Click() would work, but apparently it doesn’t. How could I do this?

Simplified example:

private void button1_Click(object sender, EventArgs e)
{
    count += 1;
    label1.Text = Convert.ToString(count);
}
private void button2_Click(object sender, EventArgs e)
{
    count += 1;
    label1.Text = Convert.ToString(count);
}

— EDIT —

I am using a class diagram which doesn’t show any additional methods that would/should do this. Need to stick to the class diagram.

  • 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-26T15:50:08+00:00Added an answer on May 26, 2026 at 3:50 pm

    You have a few options.

    1. Put the code that’s in both events into its own method and call that.
    2. Make a single _click method and set it as both button’s event handler.
    3. You could call button2_Click from button1_click (i advise against this one).

    1

    private IncrementAndDisplay()
    {
        count += 1;
        label1.Text = Convert.ToString(count);
    }
    private void button1_Click(object sender, EventArgs e)
    {
        IncrementAndDisplay();
    }
    private void button2_Click(object sender, EventArgs e)
    {
        IncrementAndDisplay();
    }
    

    2

    // Change both button's clicked events to use this method in the IDE, or in code.
    private void button_Click(object sender, EventArgs e)
    {
        count += 1;
        label1.Text = Convert.ToString(count);
    }
    

    3

    private void button1_Click(object sender, EventArgs e)
    {
        button2_Click(sender, e); // Bad!
    }
    private void button2_Click(object sender, EventArgs e)
    {
        count += 1;
        label1.Text = Convert.ToString(count);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Problem 1 I'm trying to use an Onclick event from a search button, that
I have a big red button and I'm trying to use javascript to perform
I have 3 buttons. I'm trying to get it so that when one is
ok i have 6 buttons, im trying to have a jquery listener for when
I am trying to have the button to display to the right of the
I'm trying to have a button on the self.navigationItem.rightButton that toggles a segmented control
In trying to solve the ajax back button problem I have found the Really
I'm trying to create a button with a rectangle since we're gonna have different
I'm trying to create a custom control - a button - which will have
I have buttons on a page that look like: <p> <a href=view.php> <input type=button

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.