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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T18:19:32+00:00 2026-05-16T18:19:32+00:00

I have created a WinForm and I added to it dynamic Buttons, how I

  • 0

I have created a WinForm and I added to it dynamic Buttons, how I can deal with it’s events

public static void Notify()
{

    var line = 3;

    Form fm = new Form();
    fm.Text = "Hello!";
    fm.ShowInTaskbar = false;
    fm.ShowIcon = false;
    fm.MinimizeBox = false;
    fm.MaximizeBox = false;
    fm.FormBorderStyle = FormBorderStyle.FixedToolWindow;
    fm.TopMost = true;
    fm.ClientSize = new Size(150, 75 * line/2);
    Rectangle workingArea = Screen.PrimaryScreen.WorkingArea;
    int left = workingArea.Width - fm.Width-5;
    int top = workingArea.Height - fm.Height-4;
    fm.Location = new Point(left, top);
    fm.StartPosition = FormStartPosition.Manual;

    var buttomArray = new Button[line];

    for (int i = 0; i < line; i++)
    {
        buttomArray[i] = new Button();
        buttomArray[i].Text = "Button " + (i + 1);
        buttomArray[i].Location = new Point(10,30*(i+1) - 16);
        buttomArray[i].Size = new Size(130,25);
        fm.Controls.AddRange(new Control[] { buttomArray[i] });
    }

    fm.Show();
}

I want to be able to do some different things when I click on different Button (maybe I can use the “name” as an identifier?)

cheers

  • 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-16T18:19:32+00:00Added an answer on May 16, 2026 at 6:19 pm

    Simply assign the Click handler:

    for (int i = 0; i < 10; i++)
    {
        var btn = new Button();
        btn.Text = "Button " + i;
        btn.Location = new Point(10, 30 * (i + 1) - 16);
        btn.Click += (sender, args) =>
        {
            // sender is the instance of the button that was clicked
            MessageBox.Show(((Button)sender).Text + " was clicked");
        };
        Controls.Add(btn);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've created a winform in c#, I have 3 controls on the pages and
If a set of controls on a WinForm have had DataBindings created and attached
I have created a winform for the users to view view the many reports
I have created a c# 2.0 WinForm application which loads dlls, searches for an
I have created a user control on winform where i want to display some
I have created a WinForm application in which, when I hit a key, it's
I have several controls in a winform application that I added databindings to using
I am doing college project in winform, mysql ,c#. for that I have created
I have an experimental winform which is tiny: 20 lines of added code two
I am using a C# .NET 2.0 winform in 2010, I have added 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.