0

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?

  • SuspendLayout() before the loop, ResumeLayout() after it. Tends not the solve the problem when the user controls have a lot of child controls or the FlowLayoutPanel is being misused as a grid control. Then use the form's ResizeBegin() event to temporarily hide the panel. – Hans Passant May 15 '23 at 13:13

1 Answers1

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.

nlouis56
  • 49
  • 6