一聚教程网:一个值得你收藏的教程网站

热门教程

转载:用Visual C#动态生成组件,请看!(三)

时间:2022-07-02 11:35:12 编辑:袖梨 来源:一聚教程网

下面是实现上面结果的程序源代码:
using System ;
using System.Drawing ;
using System.Collections ;
using System.ComponentModel ;
using System.Windows.Forms ;
using System.Data ;
namespace DynamicControls
{
public class Form1 : Form
{
private Button btnAdd ;
private System.ComponentModel.Container components = null ;
private Button txtAdd ;
//给产生的按钮定义一个数量计算器
private int counter ;
//给产生的按钮定义相对位置的纵坐标
private int locY ;
//给产生的文本框定义一个数量计算器
private int counter01 ;
//给产生的文本框定义相对位置的纵坐标
private int locY1 ;
public Form1 ( )
{
InitializeComponent ( ) ;
//初始化产生的按钮何文本框位置的纵坐标
locY = this.btnAdd.Location.Y ;
locY1 = this.txtAdd.Location.Y ;
}
//清除在程序中使用到的资源
protected override void Dispose ( bool disposing )
{
if ( disposing )
{
if ( components != null )
{
components.Dispose ( ) ;
}
}
base.Dispose ( disposing ) ;
}
private void InitializeComponent ( )
{
this.btnAdd = new Button ( ) ;
this.txtAdd = new Button ( ) ;
this.SuspendLayout ( ) ;
this.btnAdd.FlatStyle = FlatStyle.Popup ;
this.btnAdd.Location = new System.Drawing.Point ( 8 , 16 ) ;
this.btnAdd.Name = "btnAdd" ;
this.btnAdd.TabIndex = 0 ;
this.btnAdd.Text = "生成按钮!" ;
this.btnAdd.Click += new System.EventHandler ( this.btnAdd_Click ) ;
this.txtAdd.FlatStyle = FlatStyle.Popup ;

热门栏目