gpt4 book ai didi

javascript - 如何将标签转移到另一个容器

转载 作者:行者123 更新时间:2023-11-28 03:23:48 25 4
gpt4 key购买 nike

我想将生成的标签传输到另一个容器(即 flowLayoutpanel)中。有一个按钮将生成标签,我在生成的标签上添加了一个单击事件,但不知道如何将它们移出面板并传输到 flowlayoutpanel。

感谢您 future 的回答。

        {
System.Windows.Forms.Label lbl = new System.Windows.Forms.Label();
panel1.Controls.Add(lbl);
lbl.Top = y;
lbl.Left = l1;
lbl.Text = "a " + l1.ToString();
lbl.BackColor = Color.FromArgb(0, 0, 0, 0);
lbl.Width = 40;
lbl.Click += new EventHandler(lbl_Click);
return lbl;
}

void lbl_Click(object sender, EventArgs e)
{
Label lblclk = (Label)sender;
lblclk.Parent = new FlowLayoutPanel();// i know this part was wrong

}```

最佳答案

假设你有一个FlowLayoutPanel flowLayoutPanel1,那么点击事件会先将其从panel1中删除,然后将其添加到flowLayoutPanel1中。

    private void lbl_Click(object sender, EventArgs e)
{
Label lblclk = sender as Label;
panel1.Controls.Remove(lblclk);
flowLayoutPanel1.Controls.Add(lblclk);
}

关于javascript - 如何将标签转移到另一个容器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58866226/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com