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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T13:52:10+00:00 2026-06-12T13:52:10+00:00

I have some problems with the understanding of casting buttons, maybe you can help

  • 0

I have some problems with the understanding of casting buttons, maybe you can help me. If i have for example 3 buttons and i wont have very long code i can cast them, right?
For example:

private void button1_Click(object sender, EventArgs e)
{

}

private void button2_Click(object sender, EventArgs e)
{

}

private void button3_Click(object sender, EventArgs e)
{

}

If i give evry button a tag, i sould be able to ask if the button was clicked, right?

private void MachMalClick(object sender, EventArgs e)
{
    var myButton = (Button)sender;

    if (myButton != null)
    {
        var test = myButton.Tag;
switch (test)
            {
                case 1: MessageBox.Show("button 1 was clicked");
                    break;
                case 2: MessageBox.Show("button 2 was clicked");
                    break;
                case 3: MessageBox.Show("button 3 was clicked");
                    break;
            }
    }
}

if the upper mthode is succesful the object has to be a button (casted sender into button -> must be a button) But now i have problems to adress the tag. Can somebody help me? I dont find something on the internet and i´m sorry if this is a stupid question, but im new to c#.

  • 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-12T13:52:11+00:00Added an answer on June 12, 2026 at 1:52 pm

    You can try with Id property

    Button myButton = (Button)sender;
    if(myButton.Id == "button1")
    {
      ....
    }
    elseif(myButton.Id == "button2")
    {
       .....
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some understanding problems regarding the stringstream . Example: stringstream stream(commands); while (true)
Im having some problems understanding some code in a programme I have inherited. CGPoint
I am new to JPA and have some problems in understanding bidirectional relations. I
i have some problems on understanding gdb. i have a main function, i wrote
I'm having some problems using / understanding is_dir. (Yes, I have read the PHP
I have some problems with understanding the difference between soap:address and http:address tags in
I have some problems understanding a way to get the correct result from my
I have some problems understanding how the 'repair button' works in burn. If my
I'm a novice in iOS developing, and have some problems with understanding web service
I am not a native English speaker, so I have some problems understanding the

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.