日期:2014-05-18 浏览次数:20838 次
public partial class Form1 : Form { private Button btnobj; List<Button> btnList = new List<Button>(); private int count = 1; public Form1() { InitializeComponent(); } private void DymaControlMouseDown(object sender, EventArgs e) { Button btn = sender as Button; btn.BackColor = Color.Red; btnobj = btn; } private void button4_Click(object sender, EventArgs e) { count = ++count; int i = btnList.Count; i++; Button btn = new Button(); btn.BackColor = Color.Blue; btn.Text = ""; btn.Size = new Size(50, 60); this.toolTip1.SetToolTip(btn, "位置" + (i + 3)); btn.Click += new EventHandler(DymaControlMouseDown); btnList.Add(btn); if (i % 3 == 1) { btnList[i - 1].Location = new Point(21, 25 + ((i + 2) / 3 * 75)); } else if (i % 3 == 2) { btnList[i - 1].Location = new Point(130, 25 + ((i + 1) / 3 * 75)); } else { if (i % 3 == 0) btnList[i - 1].Location = new Point(240, 25 + i / 3 * 75); } this.panel1.Controls.Add(btn); } private void button6_Click(object sender, EventArgs e) { btnobj.BackColor = Color.Yellow; } }