'How to make it so two gifs in two separate pictureboxes can overlap each other?

My code involves two different picture boxes but they keep cutting each other out. i can't resize them because of the fact that they are gifs and resizing them will break them.

I've tried adding one of the pictureboxes to the other's control. So for example :

public FrmBossBattle()
    {   
        
        InitializeComponent();

        IdleMove.Controls.Add(bossidle); //Here I tried making the one on the right belong to the one on the left, but they still cut each other out and don't overlap properly. 


        picBoxBackground.Controls.Add(IdleMove); // IdleMove added to background
        IdleMove.Location = new Point(83, 100); // Location is added
        IdleMove.BackColor = Color.Transparent; // color is null
        IdleMove.Visible = true; //IDLE MOVE IS THE PICTURE ON THE LEFT

        
        picBoxBackground.Controls.Add(bossidle); // ANIMATION/PICTURE ON RIGHT
        bossidle.BackColor = Color.Transparent; // color = null
        bossidle.Location = new Point(368, 96); // location added
        bossidle.Visible = true; 
        

what images look like in design what images look like in output



Solution 1:[1]

If you want them to be in the same position as the design-time placement, but as children of picBoxBackground, then use code like this:

private void button1_Click_2(object sender, EventArgs e)
{
    AddToPictureBox(IdleMove, picBoxBackground);
    AddToPictureBox(bossidle, picBoxBackground);
}

private void AddToPictureBox(PictureBox child_PB, PictureBox parent_PB)
{
    Point ptChildScreen = child_PB.PointToScreen(new Point(0, 0));
    parent_PB.Controls.Add(child_PB);
    child_PB.Location = parent_PB.PointToClient(ptChildScreen);
    child_PB.BackColor = Color.Transparent;
    child_PB.Visible = true;
}

Not sure if that will actually fix your problem, but the PBs will be in the same places that you put them at during design-time.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Idle_Mind