Form1.cs 998 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. namespace WindowsFormsExtend
  11. {
  12. public partial class Form1 : Form
  13. {
  14. public Form1()
  15. {
  16. InitializeComponent();
  17. }
  18. //设置按钮为接受按钮
  19. private void Form1_Load(object sender, EventArgs e)
  20. {
  21. this.AcceptButton = button1;
  22. }
  23. //点击按钮添加控件
  24. private void button1_Click(object sender, EventArgs e)
  25. {
  26. ComboBox cbo = new ComboBox(); //创建控件的实例
  27. cbo.Location = new Point(20, 30); //设置控件添加的位置
  28. this.Controls.Add(cbo); //当前窗体所包含的控件的集合要添加cbo这个控件
  29. }
  30. private void textBox1_TextChanged(object sender, EventArgs e)
  31. {
  32. }
  33. }
  34. }