Reputation: 47
I have a procedure which draws in the player picture box, as below:
public static PictureBox drawPlayer(Engine.Tile location, Image looks)
{
PictureBox player = new PictureBox();
player.Location = location.img.Location;
player.BackColor = Color.Yellow;
player.Size = new Size(50, 50);
player.Name = "Player";
player.Visible = true;
player.BringToFront();
return player;
}
However, it is not working, it is called as such:
t.Controls.Add(drawPlayer(location, image));
Any help with this would be great or an answer as to why this doesn't work, I have temporarily set the colour of the box to yellow just to make it really stand out when it does finally decide to load.
Thanks,
Laurence
Upvotes: 1
Views: 108
Reputation: 2793
You need to use player.BringToFront();
after the control has been added into the form, as it does not exist on the form when you call this in the method that is making the PictureBox.
Upvotes: 2