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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T01:04:13+00:00 2026-06-18T01:04:13+00:00

I have a Windows form named Form1 and panel within this form named panel1

  • 0

I have a Windows form named Form1 and panel within this form named panel1. I use the panel only to place buttons there so that I can group them and work with them separately from the other buttons in my Form1. For the purpose of my program I need to handle every button click made from the buttons inside panel1. For this purpose I use the same code snippet:

  public Form1()
        {
            InitializeComponent();

            // Set a click event handler for the button in the panel
            foreach (var button in panel1.Controls.OfType<Button>())
            {

                button.Click += HandleClick;
            }
        }

What I need to do is to have a way to identify which button exactly has been clicked. For this purpose I played a little bit with my handler method:

private void HandleClick(object o, EventArgs e)
{
    MessageBox.Show("HI" + o.ToString());
}

which gave me some hope because I get this:

enter image description here

It’s the second part – Text: button4 which is actually enough information to continue with my work. But I can’t find a way to get this piece of information without some complicated string manipulations. So is there a way to get this or other unique information about the button been clicked given the way I have written my code?

  • 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-06-18T01:04:14+00:00Added an answer on June 18, 2026 at 1:04 am
        private void HandleClick(object sender, EventArgs e)
        {
            var btn = sender as Button;
            if (btn != null)
            {
                MessageBox.Show(btn.Text);
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have Windows Form named - Form1 and inside Form1 I have a panel
I have a print preview that displays a captured panel on a form 'Panel1.DrawToBitmap(memoryImage,
I have a Windows Form application with a button named loginBtn and a label
I have a windows form application. On the form there are three groupboxs. Each
I have one windows form file that each time I open it in Visual
i have a windows form that contains a bunch of textboxes. I need a
I have a windows form on the main thread and another thread that does
Guys, I have a windows form with a panel control and inside the panel
I have a class that inherits the built in System.Windows.Forms.Panel class. According to the
I have a c# windows form application that has a similar GUI functionality as

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.