如何删除C#Windows窗体中动态创建的文本框和标签?
我想知道如何删除动态创建的如何删除C#Windows窗体中动态创建的文本框和标签?,c#,textbox,labels,C#,Textbox,Labels,我想知道如何删除动态创建的文本框和标签,我想删除此事件中所有动态创建的文本框和标签。因为所有文本框和标签都基于数据库。每次事件更改,文本框和标签也将更改 到目前为止,以下是我的代码: private void cmbMethodActions_SelectedIndexChanged(object sender, EventArgs e) { GetActionFields(int.Parse(cmbMethodActions.SelectedValue.ToString
文本框
和标签
,我想删除此事件中所有动态创建的文本框
和标签
。因为所有文本框
和标签
都基于数据库。每次事件更改,文本框
和标签
也将更改
到目前为止,以下是我的代码:
private void cmbMethodActions_SelectedIndexChanged(object sender, EventArgs e)
{
GetActionFields(int.Parse(cmbMethodActions.SelectedValue.ToString()));
}
private void GetActionFields(int i)
{
MySqlCommand cmd = new MySqlCommand("call GetActionField("+i+")", cn);
MySqlDataAdapter adapter = new MySqlDataAdapter(cmd);
DataTable dt = new DataTable();
adapter.Fill(dt);
for (int x = 0; x < dt.Rows.Count; x++)
{
TextBox txtfields = new TextBox();
txtfields.Name = dt.Rows[x]["field_name"].ToString();
txtfields.Width = 175;
flowLayoutPanelText.Controls.Add(txtfields);
Label txtlbl = new Label();
txtlbl.Name = dt.Rows[x]["field_name"].ToString();
txtlbl.Text = txtlbl.Name;
flowLayoutPanelLabel.Controls.Add(txtlbl);
}
}
private void cmbMethodActions\u SelectedIndexChanged(对象发送方,事件参数e)
{
GetActionFields(int.Parse(cmbMethodActions.SelectedValue.ToString());
}
私有void GetActionFields(int i)
{
MySqlCommand cmd=newmysqlcommand(“调用GetActionField(“+i+”),cn);
MySqlDataAdapter=新的MySqlDataAdapter(cmd);
DataTable dt=新的DataTable();
适配器填充(dt);
对于(int x=0;x
flowLayoutPanelText.Controls.Clear();
flowLayoutPanelLabel.Controls.Clear();