c# - 在 FlowLayoutPanel 中插入用户控件

标签 c# .net winforms user-controls flowlayoutpanel

我有一个 FlowLayoutPanel 和几个 UserControl。现在我希望一个控件始终位于我的 FlowLayoutPanel 的底部。所以我想在最低控件上方添加我的 UserControl。有没有一种简单的方法可以在 FlowLayoutPanel 中插入用户控件?

我目前在想把底部的控件去掉,把我想加的控件加进去,再把底部的控件加进去。但是我不认为这真的是最好的方法。这里有没有人可以帮助我提供有关如何执行此操作的一些信息?

最佳答案

是的,您可以在 Flow-Layout Panel 中设置 ControlUser-ControlIndex .

//flPanel is your flow-layout panel...
flPanel.Contorls.Add(ctrl1); //ctrl1 can be any control or user control
flPanel.Contorls.Add(ctrl2); //ctrl2 can be any control or user control
flPanel.Controls.SetChildIndex(ctrl1, flPanel.Controls.GetChildIndex(ctrl2) + 1);

这样,尽管您的 ctrl1 已首先添加到您的 Flow-Layout Panel 中,但它会位于底部。

如果您有更多的 Control,并且您要在不同的事件中切换它们的可见性,那么您将必须为每个 Control 设置 Index > 每一次。

我建议将您的 Control 放在 Panel 中,并将 Panel 添加到您的 Flow-Layout Panel 中。

关于c# - 在 FlowLayoutPanel 中插入用户控件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13265635/

相关文章:

c# - 如何从 Windows 应用程序中抓取数据网格

c# - MVC3 传回带有列表的对象列表

.net - Dragablz 组件并使用不同的窗口作为宿主

c# - Renci SSH.NET : can create symlink, 但删除符号链接(symbolic link)失败,为什么?

.net - 在 Windows 窗体中加载与显示事件

c# - 在 WinForms 的 MenuStrip 和 DropDownItems 中添加和删除 ToolStripMenuItem

c# - 更改c#中菜单项附近箭头的颜色

c# - 如何在 powershell 中的单行上设置 Set-VMFirmware

c# - 无法为此 session 加载 Outlook 数据文件 (.pst)

python - IronPython 与 Python .NET