버튼을 눌러 텍스트 상자와 라벨을 하나씩 제거하려고합니다. inputTextBoxes라는 텍스트 상자 목록이 있습니다. 나는이 시도하고 제거하는버튼에서 텍스트/라벨 제거 C#
private void onClickAdd(object sender, EventArgs e)
{
inputTextBoxes = new List<TextBox>();
Label label1 = new Label();
label1.Name = "label1";
label1.Text = "w" + i;
label1.Location = new System.Drawing.Point(5, 10 + (20 * i));
label1.Size = new System.Drawing.Size(30, 20);
this.Controls.Add(label1);
TextBox text1 = new TextBox();
text1.Name = "text1";
text1.Location = new System.Drawing.Point(35, 10 + (20 * i));
text1.Size = new System.Drawing.Size(25, 20);
inputTextBoxes.Add(text1);
this.Controls.Add(text1);
i++;
}
: 여기
는 추가하는 코드입니다private void onClickRemove(object sender, EventArgs e)
{
foreach(TextBox text1 in inputTextBoxes)
{
this.Controls.Remove(text1);
}
}
을하지만 마지막 텍스트 상자가, 버튼을 againg 클릭하면하지 않습니다 추가 된 제거 아무것도.
텍스트 상자가 1 개만 있기 때문에 – Sajeetharan
이 링크 확인 - http://stackoverflow.com/questions/23326276/removing-textboxes-created-dynamically-on-button-click –
클릭하면 모든 텍스트 상자가 제거되고, 하나 하나가 아닌 – mihai11