0
我是C#的新手,我使用Windows窗体。如何在flowLayoutPanel c#中存储第一个控件?
我有flowLayoutPanel
和我编程添加一些buttons
它。 我想要做的是:我想要将位于flowLayoutPanel
的第一个button
保存为ButtonToSave
对象。
flowLayoutPanel1.FlowDirection= FlowDirection.LeftToRight
private void AddButtons_Click(object sender, EventArgs e)
{
Button btn = new Button();
flowLayoutPanel1.Controls.Add(btn);
}
private void StoreTheFirstButton_Click(object sender, EventArgs e)
{
Button ButtonToSave = new Button();
ButtonToSave = "First button in flowLayoutPanel1"
}
任何人都知道如何保存位于flowLayoutPanel1
的第一个按钮进入ButtonToSave
在引发StoreTheFirstButton
事件?
谢谢
这不是显而易见的,为什么它必须是一个变量。尤其不是局部变量。只要你用'flowLayoutPanel1.Controls.OfType
@Hans Passant找回它。你的答案是非常正确的,它按我的意愿工作,请将其作为答案。谢谢 – user8074669
请使用它来完成您开始的Q + A,只是将我的评论标记为已过时。 –