你试试下面的方法吧,测试过没有问题,怎么添加timer我就不用说了吧
private void timer1_Tick(object sender, EventArgs e)
{
if (newPanel.Controls.Count == 0)
{
for (int i = 0; i < 4; i++)
{
RadioButton radio = new RadioButton();
radio.Text = "radio" + i.ToString();
radio.Location = new Point(50, i * 30);
newPanel.Controls.Add(radio);
}
}
else
{
int count = newPanel.Controls.Count;
for (int i = 0; i < count; i++)
{
newPanel.Controls[0].Dispose();
}
}
}
private void button3_Click(object sender, EventArgs e)
{
System.Windows.Forms.RadioButton radio = new RadioButton();
radio.Visible = true;
this.panel1.Controls.Add(radio);
radio.Location = new Point(100, 100);
radio.Text = "radio1";
System.Windows.Forms.RadioButton radio1 = new RadioButton();
radio1.Visible = true;
this.panel1.Controls.Add(radio1);
radio1.Location = new Point(150, 150);
radio1.Text = "radio2";
}
//清除所有控件
private void button4_Click(object sender, EventArgs e)
{
this.panel1.Controls.Clear();
}