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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:46:59+00:00 2026-05-26T12:46:59+00:00

I have a Windows Forms application containing around 15 different buttons which on-click should

  • 0

I have a Windows Forms application containing around 15 different buttons which on-click should display either 1 or 0.

Now the problem:
Currently i’m repeating almost the exact same code for each and every button and that works fine, but what i would like to do is some method that knows which button i’m currently pressing and then i would like to send that buttons name as a parameter to the function which contains the code.

This is how i’m doing it now:

    private: System::Void button1Click(System::Object^  sender, System::Windows::Forms::MouseEventArgs^  e) { 
   //CODE HERE
 }
    private: System::Void button2Click(System::Object^  sender, System::Windows::Forms::MouseEventArgs^  e) { 
   //SAME CODE HERE
 }

And this goes on until button 15…

What i would like to do:

private: System::Void justClicked(System::Object^  sender, System::Windows::Forms::MouseEventArgs^  e) { 
       //CODE HERE with justClicked as the buttons name.
     }
  • 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-26T12:47:00+00:00Added an answer on May 26, 2026 at 12:47 pm

    The sender parameter, though defined as an object, is the reference to the object that caused the event. All you have to do is cast sender to a Button, or Control, to get the name or whatever property you need.

    You also just need a single event handler. All your buttons’ Click events should be assigned to the same event handler function.

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

Sidebar

Related Questions

I have a Windows Forms application (C#) containing a ListBox into which I have
The Scenario I have a windows forms application containing a MAINFORM with a listbox
I have got a problem. I have windows forms application with dynamic generated layout,
I have a windows forms application containing a datagridview control. The datagridview is populated
I have a windows forms application on which I need to use a for
I have a Windows Forms application which makes calls to web services via proxies
I have a Windows Forms application built using the .NET 3.5 Framework which self
I have windows forms application wich runs another console application here is the part
I have a Windows Forms application that I wrote that does some monitoring of
I have a Windows Forms application in C#/Visual Studio 2008 with an IE WebBrowser

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.