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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T17:55:49+00:00 2026-05-21T17:55:49+00:00

I’m using 2 classes that contains buttons; I added their buttons in my main

  • 0

I’m using 2 classes that contains buttons; I added their buttons in my main form, and now I want to do something when the user clicks on one of them. For example, if the user clicks on the button that’s defined in class1, the text of all the buttons that are defined in class1 should change to “class1”. Actually, I need to find the class of a button to change other variables in that class.

  • 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-21T17:55:49+00:00Added an answer on May 21, 2026 at 5:55 pm

    In your class, assign event handlers for the click event on the buttons so when you add them to the form and they’re clicked the event handler will fire off inside of your class so you can access the class properties.

    Otherwise, add the class reference to the button’s Tag property.

       class Class1
        {
    
            public Button MyButton { get; set; }
    
            public Class1()
            {
                MyButton = new Button();
                MyButton.Click += new EventHandler(MyButton_Click);
            }
    
            void MyButton_Click(object sender, EventArgs e)
            {
                //Do code here
            }
    
        }
    
    public partial class Form1 : Form
        {
            Class1 c1 = new Class1();
    
            public Form1()
            {
                InitializeComponent();
            }
    
            private void Form1_Load(object sender, EventArgs e)
            {
                c1.MyButton.Width = 100;
                c1.MyButton.Height = 100;
                c1.MyButton.Top = 0;
                c1.MyButton.Left = 0;
                this.Controls.Add(c1.MyButton);
    
    
            }
    

    OR

    class Class1 : IButtonClass
        {
    
            public Button MyButton { get; set; }
    
            public Class1()
            {
                MyButton = new Button();
                MyButton.Tag = this;        
            }
    
            public void DoSoemthing()
            {
                //Do something
            }
    
        }
    
        interface IButtonClass
        {
            void DoSoemthing();
        }
    
    public partial class Form1 : Form
        {
            Class1 c1 = new Class1();
    
            public Form1()
            {
                InitializeComponent();
            }
    
            private void Form1_Load(object sender, EventArgs e)
            {
                c1.MyButton.Width = 100;
                c1.MyButton.Height = 100;
                c1.MyButton.Top = 0;
                c1.MyButton.Left = 0;
                this.Controls.Add(c1.MyButton);
    
                c1.MyButton.Click += new EventHandler(MyButton_Click);
            }
    
        void MyButton_Click(object sender, EventArgs e)
        {
            IButtonClass c = ((Button)sender).Tag as IButtonClass;
            c.DoSoemthing();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm making a simple page using Google Maps API 3. My first. One marker
We're building an app, our first using Rails 3, and we're having to build
I have a bunch of posts stored in text files formatted in yaml/textile (from
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I am trying to loop through a bunch of documents I have to put
I have some data like this: 1 2 3 4 5 9 2 6

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.