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;
            }
        }        
    }

So does a hundred views but no comments mean I should elaborate on my code more or show more? Maybe I left some key parts out? I'm kinda new at this and didn't want to give too much overhead that was unnecessary since the code is starting to grow. Or does it mean that the code should be working correctly? Even just a quick "What the hell are you doing?" will help me try to clear up the confusion. I'm stuck here and everything I do seems to print the same empty panel.

So does a hundred views but no comments mean I should elaborate on my code more or show more? Maybe I left some key parts out? I'm kinda new at this and didn't want to give too much overhead that was unnecessary since the code is starting to grow. Or does it mean that the code should be working correctly? Even just a quick "What the hell are you doing?" will help me try to clear up the confusion. I'm stuck here and everything I do seems to print the same empty panel.

LOL--I like your attitude.;) There are people in her more graphic oriented than I am, but if they don't jump in by the time I revisit tomorrow, I will dive in... If in the meantime, you come up with a small breakthrough and narrowed down issue related, do post that update..

Cheers!

EDIT: There are people in here from all over the world in different time zones, so it probably won't be much longer before someone jumps in... I'm about to go to bed myself.

Edited 7 Years Ago by DdoubleD: n/a

Thanks dude for the post. I appreciate it. I will dive into it when I get the chance, sadly its a side surprise project for my little sister that I wanted to try out and so it keeps getting put on the back-burner. Once I ran headlong into this graphics thing, I kinda just came to a halt and decided to stop ignoring the homework I had building up.

But, like you said, if no one answers, I'll try a few more things and then elaborate on my issue.

Update: I decided to take a chance here and change around some things. One of which was changing one line to:

//unitSelectGrid.Size = new Size(55, (((player1Units.Count + 1)/2)*30) - 5);

and changing the panel to growOnly rather then ShrinkandGrow. It now works, though it doesn't print how I expected... so it must be a math error. I don't know if this is actually solving my problem though ha, because I'm curious what I was doing wrong in the beginning.

I don't know if this is actually solving my problem though ha, because I'm curious what I was doing wrong in the beginning.

Nvm, I'm just retarded at math. Sorry about the inconvenience anyone had reading my code. I don't mean to waste people's time. Thank you for the help but this is now fixed.

This happens to me all the time, i post a problem then fix it myself...even if i've spent horus trying before posting. In fact, more than once i have solved the problem WHILST writing the post haha, somehow organising things in the post to make them understandable to readers, also gets them straight in my head and i see the problem :p

Remember to mark thte thread as solved as you answered your own question :D

This question has already been answered. Start a new discussion instead.