When I draw several images in a loop with some overlapping, like a deck of playing cards, I want the last card to be on top, to see the whole card. Now it's the first card that is visible. I wonder if there is a way to bring the first card to front or something equal?
for (int i = 1; i < 10; i++)
{
cardGui = new CardGui(i);
cardGui.Location = new Point(10 + (i * 10), 10);
panel1.Controls.Add(cardGui);
}
Try this code after your loop:
for (int i = 1; i < 10; i++)
{
cardGui = new CardGui(i);
cardGui.Location = new Point(10 + (i * 10), 10);
panel1.Controls.Add(cardGui);
}
cardGui.BringToFront();
I want the last card to be on top
This code gives exactly what you asked
Try BringToFront()
method or use SetChildIndex
method of the parent's Controls
collection.
SetChildIndex
: Sets the index of the specified child control in the collection to the specified index.
BringToFront
: Brings the control to the front of the z-order.
for a sample code:
for (int i = 1; i < 10; i++)
{
cardGui = new CardGui(i);
cardGui.Location = new Point(10 + (i * 10), 10);
panel1.Controls.Add(cardGui);
panel1.Controls.SetChildIndex(cardGui, 10 - i);
}
If you want to bring the first card to front you should have 2 values for the card for example cardGui1 and cardGui2. the first one is only for being the front the others for completing the loop.
Try this :
const j =1;
cardGui2 = new cardGui2(j);
cardGui12.Location = new Point(10 + (j * 10), 10);
panel1.Controls.Add(cardGui2);
cardGui2.BringToFront();
for (int i = 1; i < 10; i++)
{
cardGui1 = new CardGui1(i);
cardGui1.Location = new Point(10 + (i * 10), 10);
panel1.Controls.Add(cardGui1);
}
Update :
I assume the last card index is 10. Try this:
for (int i = 1; i < 10; i++)
{
cardGui1 = new CardGui1(i);
cardGui1.Location = new Point(10 + (i * 10), 10);
panel1.Controls.Add(cardGui1);
}
const j =10;
cardGui2 = new cardGui2(j);
cardGui12.Location = new Point(10 + (j * 10), 10);
panel1.Controls.Add(cardGui2);
cardGui2.BringToFront();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.