0

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

vanilliqs
  • 3
  • 3
  • _bossidle.Location = new Point(368, 96);_ is this really relative to the parent? – TaW Feb 01 '22 at 09:37
  • What do you mean? – vanilliqs Feb 01 '22 at 12:39
  • I meant just what I wrote. Location should always be relative to the Parent control, not the Form. Is `picBoxBackground` avtually wide enough to sgow a child at x=368 ? - Also: The figure to the right seems to be cut off. Is there any other control? - Also: Do note that while you can freely __nest__ controls, as you do, you can't make them __overlap,__ i.e. once the figures get closer one will be on top of the other and no working transparency will apply.. – TaW Feb 01 '22 at 15:03
  • Yeah, that's exactly the problem I'm facing. I understand with the location now btw, i'll try to extend the form, thanks. Also, since you said you can't make these overlap, do you have any suggestions for an alternative I can use that does allow gifs to overlap? I'm unsure about drawing them because there are a lot of frames and I'm not familiar with Graphic. – vanilliqs Feb 01 '22 at 19:58
  • Well it is a Winforms limitation and drawing them is the only winforms alternative. WPF would be the recommended way for any kind of animation, but there is a steep learning cirbe, imo.. – TaW Feb 02 '22 at 05:45

1 Answers1

0

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.

Idle_Mind
  • 38,363
  • 3
  • 29
  • 40
  • Do I have to use button_click? I dont want my user to have to click a button to make that happen – vanilliqs Feb 01 '22 at 12:40
  • Of course not...put it in the `Load()` event of the form maybe? Or the constructor like you've got your other code. – Idle_Mind Feb 01 '22 at 13:17