I want to know if this is possible in C # winform.
create a control when the button is pressed and place it in the specified location.
I think it's possible
private TextBox txtBox = new TextBox(); private Button btnAdd = new Button(); private ListBox lstBox = new ListBox(); private CheckBox chkBox = new CheckBox(); private Label lblCount = new Label();
but the problem is that when the button is pressed, the same controls are created. How to avoid this
What yes ........ I wrote, and I did not expect this exception, because the control already has btnAdd , since many buttons create as many as you want. Access to them will be a problem, but it will be solved by @drachenstern method correctly?
private void button1_Click_1(object sender, EventArgs e) { Button btnAdd = new Button(); btnAdd.BackColor = Color.Gray; btnAdd.Text = "Add"; btnAdd.Location = new System.Drawing.Point(90, 25+i); btnAdd.Size = new System.Drawing.Size(50, 25); this.Controls.Add(btnAdd); i = i + 10; }
source share