0

I have a problem with the drawing and or the filling speed of my FlowLayoutPanel.
See screenshot.
Can I speedup the process my cashing my images somehow?
Or is there a better alternative to the FlowLayoutPanel?

private void FillPanel()
{
	flpServices.Controls.Clear();
	
	prevStatus = 0;
	prevRows = 0;
	foreach (Jims.Services s in serviceList)
	{
		PictureBox pt = new PictureBox();
		
		pt.ImageLocation = @""+ imgloc + (int)s.Status + ".png";
		pt.SizeMode = PictureBoxSizeMode.StretchImage;
		pt.Width = 32;
		pt.Height = 32;
		pt.Tag = s.App_Name;
		pt.Click += new EventHandler(PictureBoxClick);

		Label lbl = new Label();
		lbl.Text = s.App_Name + ": " + s.Project_Name;
		lbl.Width = flpServices.Width - pt.Width - 30;
		lbl.Height = 32;
		lbl.TextAlign = ContentAlignment.MiddleLeft;

		flpServices.Controls.Add(pt);
		flpServices.Controls.Add(lbl);
		flpServices.SetFlowBreak(lbl, true);

		prevRows++;
		prevStatus += (int)s.Status;
	}
	IconChanger();
}
3
Contributors
4
Replies
6
Views
7 Years
Discussion Span
Last Post by stratemeyerjw
0

Image.FromFile() is faster than ImageLocation. Use pt.Image=Image.FromFile("file").

Thanks that's better but still not perfect, I still see the drawing of the items...
What other ways of handling dynamic content is there?

0

I've come up with one solutions and that's to reuse the controls already in the panel. So instead of clearing the panel I change the label text and the image.

private void FillPanel()
{
	prevStatus = 0;
	prevRows = 0;

	//number of rows to be adden or removed
	int dif = (flpServices.Controls.Count / 2) - serviceList.Count; 
	
	if (dif < 0) //More rows needed
	{
		for (int i = 0; i > dif; i--)
		{
			//Create empty Picturebox
			PictureBox pt = new PictureBox();
			pt.SizeMode = PictureBoxSizeMode.StretchImage;
			pt.Width = 32;
			pt.Height = 32;
			pt.Click += new EventHandler(PictureBoxClick);

			//Create empty Label
			Label lbl = new Label();
			lbl.Width = flpServices.Width - pt.Width - 30;
			lbl.Height = 32;
			lbl.TextAlign = ContentAlignment.MiddleLeft;

			//Add the PictureBox and the Label to the panel
			flpServices.Controls.Add(pt);
			flpServices.Controls.Add(lbl);
			flpServices.SetFlowBreak(lbl, true);

		}
	}
	else if (dif > 0) //Fewer rows neded
	{
		while (dif > 0)
		{
			//Remove the PictureBox and the Label to the panel
			flpServices.Controls.RemoveAt(flpServices.Controls.Count-1);
			flpServices.Controls.RemoveAt(flpServices.Controls.Count-1);
			dif--;
		}
	}

	int row = 0;
	//Update the controls in the panel.
	foreach (Jims.Services s in serviceList)
	{
		UpdateFLPRow(s, row);

		row += 2;

		prevRows++;
		prevStatus += (int)s.Status;
	}	
	IconChanger();
}

private void UpdateFLPRow(Jims.Services s,int row)
{
	((PictureBox)flpServices.Controls[row]).Image = Image.FromFile(@"" + imgloc + (int)s.Status + ".png");
	((PictureBox)flpServices.Controls[row]).Tag = s.App_Name;
	((Label)flpServices.Controls[row + 1]).Text = s.App_Name + ": " + s.Project_Name;
}
0

Try this; drop this method in your code.

protected override CreateParams CreateParams
        {
            get
             {
               CreateParams cp = base.CreateParams;
               cp.ExStyle |= 0x02000000;
               return cp;
             }
        }

Hope this helps,
Jay Stratemeyer

Edited by stratemeyerjw: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.