Riccardo

Riccardo

  • NA
  • 1
  • 0

c# FlowLayoutPanel

Aug 18 2009 6:18 AM
Hi to all,
             I'm trying to use the FlowLayoutPanel in my form using the Framework 3.5 with Visual Studio 2008. I start my simple project by adding a form, then add a FlowLayoutPanel to the form. I set the FlowLayoutPanel Dock properties to Fill and the Autoscroll to true. This is the code of the form:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace TestLayout
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();

for (int i = 0; i < 500; i++)
{
//Create a new panel
Panel p = new Panel();

//Set the panel size
p.Size = new Size(350, 350);
//Set the border for make the panel visible
p.BorderStyle = BorderStyle.FixedSingle;

//Create a new label used for display the panel number
Label lb = new Label();
lb.Text = i.ToString();

//Add the label to the panel
p.Controls.Add(lb);

//Add the panel to the FlowLayoutPanel
flowLayoutPanel1.Controls.Add(p);
}
}
}
}

When the form start it dispay correctly the 500 panel inside the FlowLayoutPanel but if you try to do this:
  1. Scroll down to the last panel, where the label is 499
  2. Maximize the form
  3. Scroll up to the first panel, where the label is 0
You'll see that there is a first panel, than there is empty space, and then panel again but with wrong number. If you try to scroll the panel, maximize the form and the scroll again you'll find a lot of problem with the internal panel. I've try to reduce the number of internal panel but the problem persist. If I reduce the internal panel dimension from 350x350 to 100x100 the panel seems work fine. I've try to modify a lot the internal panel dimesion and I've seen that if the internal panel is big the component always fail.
I've also tryed the PerformLayout and the Refresh method on form resize but the result is the same.
There is someone that could help me with this strange problem?
Thank so much to all