using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace WindowsFormsExtend { public partial class Form1 : Form { public Form1() { InitializeComponent(); } //设置按钮为接受按钮 private void Form1_Load(object sender, EventArgs e) { this.AcceptButton = button1; } //点击按钮添加控件 private void button1_Click(object sender, EventArgs e) { ComboBox cbo = new ComboBox(); //创建控件的实例 cbo.Location = new Point(20, 30); //设置控件添加的位置 this.Controls.Add(cbo); //当前窗体所包含的控件的集合要添加cbo这个控件 } private void textBox1_TextChanged(object sender, EventArgs e) { } } }