views:

23

answers:

2

I'm playing around with a project, C# .NET 4, and I'm kind of stuck. I have with a panel that will be dynamically filled with checkboxes based on the number of items in a folder, which works fine.

But when I resize the form I want the checkboxes to move in the panel, like a little grid of checkboxes that takes up what space it can.

Thus far I have been unsuccessful in finding an efficient way to do this. I still haven't gotten it to work flat out yet, but I don't know that it matters. The methods I'm trying are resource killers.

ie.

int boxCount = panel1.Size.Width/123;
int x = 3, y = 3, i = 0;

foreach (Control chkbox in panel1.Controls)
{

      if (i < boxCount)
      {
            chkbox.Location = new Point(x, y);
            x += 123;
      }
      else
      {
            i = 0;
            x = 3;
            y += 123;
            chkbox.Location = new Point(x, y);
      }

      i++;
}

I'm looking for something that doesn't put my CPU in a choke hold and turn my form into a 3 page flip book when I resize it. For reference, I had something like the Windows desktop wallpaper selector in 7 in mind, minus the resizing of the actual controls.

I've not worked with WPF, but I am likely to start having been shown the light, so I was looking a garden variety Windows Forms solution.

+2  A: 

It sounds like you're looking for the FlowLayoutPanel.

Jacob
+1. You were quicker.
David Stratton
That works beautifully. I remember thinking there should be a control for this, but never looked. Thanks!
Ryan
A: 

Would a TableLayoutPanel or a FlowLayoutPanel meet your needs?

David Stratton