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事件" );
}
}
}
//注意:主要是看事件
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
原文链接:http://HdhCmsTest123si.org/c_sharp/108.html
dy("nrwz");
查看更多关于C#动态创建button按钮的方法实例详解的详细内容...