As I'm no expert using C#'s forms, I'm hoping I can get pointed in the right direction, as a particular section of code I have runs slow and i'm not sure how to speed it up.
The way I have it now, I have the user select a image and a tile size.
Based on the dimensions of the image and the selected tile size, I've been drawing images over top the main image. These images are the tile size with a number that fills the main images dimensions. I want them to act like buttons when I click on them. These images so far have been made as panels for this purpose.
It wouldn't be so bad if I didn't have to re calculate how many panels I need every time the user changes the image or the tile size. But as is, it chugs for about half a second, especially at lower tile sizes.
So in other words, since I have to make a lot of images/controls and display them dynamically, what would you recommend I do to be efficient about it?
What I have so far bellow.
pictureBox.Controls.Clear();
//Create our large list of buttons
for (int y = 0; y < tileCountHeight; y++)
{
for (int x = 0; x < tileCountWidth; x++)
{
Panel newPicture = new Panel();
int locX = x * tileSize;
int locY = y * tileSize;
newPicture.Location = new Point(locX, locY);
//Determine the starting image
int dataIndex = x + (y * tileCountWidth);
if (passabilityList.Count >= dataIndex)
{
passabilityList.Add(Passability.Passable);
}
switch (passabilityList[dataIndex])
{
case Passability.Blocked:
newPicture.BackgroundImage = SquareImage;
break;
case Passability.HideBehind:
newPicture.BackgroundImage = TriangleImage;
break;
case Passability.Passable:
newPicture.BackgroundImage = CircleImage;
break;
}
newPicture.Width = tileSize;
newPicture.Height = tileSize;
newPicture.Visible = true;
newPicture.BackgroundImageLayout = ImageLayout.Center;
newPicture.Name = "picOptionX" + x + "Y" + y;
pictureBox.Controls.Add(newPicture);
}
}