C Dynamic Creation of button Button Method Example Detailed Explanation

  • 2021-12-19 06:34:35
  • OfStack

C # Dynamic Creation of button Button Method Example Detailed Explanation

Dynamic creation is often needed in C # programming. This paper mainly introduces the method of dynamic creation of button button by C #, and involves the related skills of dynamic setting of C # button attributes for reference. The specific implementation method is as follows:

Examples:


using System;
 
using System.Collections.Generic;
 
using System.ComponentModel;
 
using System.Data;
 
using System.Drawing;
 
using System.Linq;
 
using System.Text;
 
using System.Windows.Forms;
 
using System.Reflection;
 
namespace App
 
{
 
 public partial class Form1 : Form
 
 {
 
  public Form1()
 
  {
 
   InitializeComponent();
 
   System.Windows.Forms.Button button = new Button();
 
   button.Text = " Button ";
 
   button.Size = new Size(100, 30);
 
   button.Location = new Point(0, 0);
 
   button.Click += delegate
 
   {
 
    ButtonClick();
 
   };
 
   this.Controls.Add(button);
 
  }
 
  void ButtonClick()
 
  {
 
   MessageBox.Show(" Clicked click Events ");
 
  }
 
 }
 
}
 
// Note: Mainly look at events 

Thank you for reading, hope to help everyone, thank you for your support to this site!


Related articles: