将用户控件的缩放调整到flowlayoutpanel的宽度。

huangapple go评论62阅读模式
英文:

scaling user controlls to the width of flowlayoutpanel

问题

以下是您要翻译的代码部分:

我有一个FlowLayoutPanel,它使用锚定到四个边缘,以便随着窗体大小的变化而缩放。我动态地向它添加一些用户控件。我希望用户控件在垂直方向上与FlowLayoutPanel一起缩放。我尝试了以下方法:

public void OnSizeChange(object? sender, EventArgs e)
{
    foreach (UserControl cont in controls)
    {
        cont.Width = flowLayoutPanel1.ClientSize.Width - 10;
    }
}

并将此函数添加到窗体的SizeChanged事件中,但在调整窗口大小时会出现性能问题。是否有更有效的方法可以实现这一点?

英文:

i have a flowlayoutpanel with anchors to all 4 sides so it scales with the form size. i'm adding some user controls to it dynamicly. i want the user controls to scale with the flowlayoupanel verticaly. i tried this approach:

public void OnSizeChange(object? sender, EventArgs e)
        {
            foreach (UserControl cont in controls)
            {
                cont.Width = flowLayoutPanel1.ClientSize.Width - 10;
            }
        }

and adding this function to form SizeChanged event but this is too laggy when resizing the window. is there a more efficient way to do it?

答案1

得分: 0

这个问题可能对你有帮助,它似乎描述了你遇到的相同问题。

基本上,解决方案似乎是你发布的代码的升级版本,我不知道性能改进是否显著。

英文:

This question might help you, it seems to describe the same problem you're having

Basically the solution seems to be a glorified version of the code you posted, I don't know if the performance improvement is significant.

huangapple
  • 本文由 发表于 2023年5月15日 15:32:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/76251795.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定