查找 FlowLayoutPanel 的行和列
只是想知道是否有一种方法可以轻松查找 FlowLayoutPanel 中当前的行和列,或者是否需要手动计算?
Just wondering if there is a way to easily lookup the rows and columns currently in a FlowLayoutPanel or if a manual calculation is required?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
该线程很旧,但我今天才收到要求,并且 GetFlowBreak 未能在导致流程面板中断到新行的控件上返回 true。我不知道为什么,而且我没有时间去弄清楚。这适用于 FlowDirection = LeftToRight。
坦白说,我没有时间写这个,但无论如何我还是有时间。这是一个简单的扩展方法,它将计算行数:
使用:
HTH!
CT
This thread is old yet I had the requirement just today and GetFlowBreak was failing to return true on a control that caused the flow panel to break onto a new line. I am not sure why and I didn't have time to figure it out. This works for FlowDirection = LeftToRight.
Frankly, I don't have time to write this but I am anyway. Here is a simple extension method that will calculate the number of rows:
Use:
HTH!
CT
上面的例子对我来说不起作用。它从未根据
FlowLayoutPanel
大小给出正确的行数。所以我更新了上面的解决方案。假设
FlowLayoutPanel
中的所有控件都具有相同的大小:在相同控件的情况下,您不需要使用此方法迭代控件
The above example was not working for me. It never gave the correct number of rows depending on the
FlowLayoutPanel
size..So I updated the solution above. Assuming, that all controls in the
FlowLayoutPanel
have same size:In the case of same controls, you don't need to iterate through the controls with this method
我找到了一个非常简单的方法来确定这一点。您必须考虑边距和填充。我只是碰巧使用了 2 的边距和 0 的填充,所以我使用了较小的左侧位置值。 X 位置具有较小值的任何控件都将位于流程布局面板的左侧旁边。如果您想计算顶部控件的数量,只需检查 Y 位置值即可。
I found a very simple way to determine this. You have to account for margins and padding. I just happened to be using a margin of 2 and padding of 0, so I used a smaller left location value. Any controls with that small value for the X location will be next to the left of the flowlayout panel. If you wanted to count the number of controls at the top just check the Y location value instead.
下面是一个使用 linq 计算高度的示例:
Here is an example using linq to calculate the height: