Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

add dynamically buttons in loop with events winform c#

for (int i = 0; i < 5; i++)
     {
        Button button = new Button();
        button.Location = new Point(160, 30 * i + 10);
        button.Click += new EventHandler(ButtonClickOneEvent);
        button.Tag = i;
        this.Controls.Add(button);
     }

void ButtonClickOneEvent(object sender, EventArgs e)
  {
     Button button = sender as Button;
     if (button != null)
     {
        // now you know the button that was clicked
        switch ((int)button.Tag)
        {
           case 0:
              // First Button Clicked
              break;
           case 1:
              // Second Button Clicked
              break;
           // ...
        }
     }
  }
Comment

PREVIOUS NEXT
Code Example
Csharp :: hide game obj oncollisionenter 
Csharp :: addding two numebrs with c# 
Csharp :: unity google play games plugin spam 
Csharp :: c# write text before user input 
Csharp :: c# date to string yyyy-mm-dd 
Csharp :: xamarin picker item 
Csharp :: get random from list c# 
Csharp :: nepali phone number regex 
Csharp :: unity mesh showing Instance 
Csharp :: Request.ServerVariables["HTTP_X_FORWARDED_FOR"] get only one ipaddress 
Csharp :: listview disable resize columns 
Csharp :: C# inline question mark on object 
Csharp :: c# datatable copy selected rows to another table 
Csharp :: gcd c# 
Csharp :: how to generate random letters in C# 
Csharp :: unity detect object with raycast 
Csharp :: c# byte array to string 
Csharp :: fair division 
Csharp :: get enum int by name 
Csharp :: unity knowing when 0 input is pressed 
Csharp :: assign long value c# 
Csharp :: c# stringbuilder to file 
Csharp :: conditional blazor styles 
Csharp :: DateTime previous day c# 
Csharp :: loop through all enum values in C# 
Csharp :: ggdesign 
Csharp :: how to cjeck if a string has a word c# 
Csharp :: c# convert string to int 
Csharp :: c# list index 
Csharp :: how to save a c# dictionary 
ADD CONTENT
Topic
Content
Source link
Name
5+9 =