Answer the question
In order to leave comments, you need to log in
How to dynamically create new buttons?
Here I have buttons, like a squeak:
11button
12button
13button
I press 1 button -> all the old buttons disappear and new ones appear, like
21button
22button
23button I press
some other one, again everything disappears and new ones appear, like
31button
32button
33button
may not clearly defined the question, but I think the essence is clear. So how is this to be implemented?
Answer the question
In order to leave comments, you need to log in
private static int n = 0;
private void button1_Click(object sender, EventArgs e)
{
var newButton = new Button()
{
Name = "btn" + n,
Text = n.ToString(),
Location = new Point(10, 10 + n*30),
Size = new Size(50, 25),
TabIndex = 100 + n,
};
n++;
this.Controls.Add(newButton);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question