C#动态创建button按钮的方法实例详解
C#动态创建button按钮的方法实例详解
C#编程中经常需要动态创建,本文主要介绍C#动态创建button按钮的方法,涉及C#按钮属性动态设置的相关技巧,以供借鉴参考。具体实现方法如下:
例子:
usingSystem;
usingSystem.Collections.Generic;
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Linq;
usingSystem.Text;
usingSystem.Windows.Forms;
usingSystem.Reflection;
namespaceApp
{
publicpartialclassForm1:Form
{
publicForm1()
{
InitializeComponent();
System.Windows.Forms.Buttonbutton=newButton();
button.Text="按钮";
button.Size=newSize(100,30);
button.Location=newPoint(0,0);
button.Click+=delegate
{
ButtonClick();
};
this.Controls.Add(button);
}
voidButtonClick()
{
MessageBox.Show("点击了click事件");
}
}
}
//注意:主要是看事件
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
