在flowlayoutpanel中动态添加控件 [英] Add controls dynamically in flowlayoutpanel
本文介绍了在flowlayoutpanel中动态添加控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在Windows窗体中,我可以通过执行以下操作来动态添加控件:
In a windows form, I can add control dynamically by doing this:
for (int i = 0; i < 5; i++)
{
Button button = new Button();
button.Location = new Point(160, 30 * i + 10);
button.Tag = i;
this.Controls.Add(button);
}
如何在FlowLayoutPanel
中动态添加控件?
How do I add controls dynamically in a FlowLayoutPanel
?
推荐答案
对于FlowLayoutPanel
,由于控件是为您安排的,因此您无需指定位置.只需将"flowLayoutPanel1
"更改为您的FlowLayoutPanel
的名称:
For a FlowLayoutPanel
, you don't need to specify a location since the controls are arranged for you. Just change "flowLayoutPanel1
" to the name of your FlowLayoutPanel
:
for (int i = 0; i < 5; i++)
{
Button button = new Button();
button.Tag = i;
flowLayoutPanel1.Controls.Add(button);
}
这篇关于在flowlayoutpanel中动态添加控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文