加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

C#动态创建button按钮的方法实例详解

发布时间:2020-12-15 06:05:05 所属栏目:百科 来源:网络整理
导读:C#动态创建button按钮的方法实例详解 C#编程中经常需要动态创建,本文主要介绍C#动态创建button按钮的方法,涉及C#按钮属性动态设置的相关技巧,以供借鉴参考。具体实现方法如下: 例子: using System; using System.Collections.Generic; using System.Com

C#动态创建button按钮的方法实例详解

C#编程中经常需要动态创建,本文主要介绍C#动态创建button按钮的方法,涉及C#按钮属性动态设置的相关技巧,以供借鉴参考。具体实现方法如下:

例子:

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.Size = new Size(100,30);
 
   button.Location = new Point(0,0);
 
   button.Click += delegate
 
   {
 
    ButtonClick();
 
   };
 
   this.Controls.Add(button);
 
  }
 
  void ButtonClick()
 
  {
 
   MessageBox.Show("点击了click事件");
 
  }
 
 }
 
}
 
//注意:主要是看事件

感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读