Hey, my problem basically is that I have no idea why images that I am loading from my files are not getting printed to this little panel I've created. Basically, the functionality i have is that users select units and then I want to lay out all the units that they have selected when they are done and have them click on them and then click where they want to place them on a map. If there is another way to go about this, then let me know, but basically every unit has a name that can be translated to an image file by just appending .JPG to it. I have tried with picture boxes and panels, but all I keep printing out is an empty panel. Any suggestions?
private void doneSelecting_Click(object sender, EventArgs e)
{
//THERE IS CODE ABOVE, but nothing important to my problem
else if (player2SelectUnits)
{
//only do this if we have two players (may do more in the future)
if (numberOfPlayers == 2)
{
//we are now done buying units, it is time to place them onto the map
//switch up the controls and the players
player2SelectUnits = false;
player1DropUnits = true;
player2DropUnits = true;
selectUnitsLabel.Text = "Player 1's Turn to Place Units. Click on the Units"
+ "\nand place them on a valid square on the map";
//hide and deactivate all the UpDowns and the images of those units
testUpDown.Enabled = false;
testUpDown.Hide();
pictureBox1.Hide();
//hide and deactivate the finish button
doneSelecting.Enabled = false;
doneSelecting.Hide();
//now that it will be starting to drag and drop all those units on the map
//we will have to dynamically load all the players pieces onto the control panel.
unitSelectGrid.Enabled = true;
unitSelectGrid.Size = new Size(55, (((player1Units.Count + 1)/2)*30) - 5);
unitSelectGrid.Paint += new PaintEventHandler(paintSelectUnits);
unitSelectGrid.Show();
unitSelectGrid.Invalidate();
}
}
}
private void paintSelectUnits(object sender, PaintEventArgs e)
{
int i = 0;
int j = 0;
foreach (Unit u in player1Units)
{
String name = u.getName();
name = String.Concat(name, ".JPG");
name = String.Concat(unitDirectory, name);
e.Graphics.DrawImage(Image.FromFile(name), unitSelectGrid.Location.X + (30 * (i % 2)),
unitSelectGrid.Location.Y + (30 * j), 25, 25);
++i;
if (i % 2 == 0)
{
++j;
}
}
}