0

I'm tryin to make picbox2 back color to transparent when the picbox1 pass over picbox2. This is my code

namespace Gioco
{
public partial class Form1 : Form
{
    Image img;
    Image tmpSx;
    Image tmpDx;
    Image tmpUp;
    Image tmpDw;

    public Form1()
    {
        InitializeComponent();
        panel1.Controls.Add(pictureBox1);
        pictureBox1.Parent = panel1;
        img = pictureBox1.Image;
        tmpSx = (Image)img.Clone();
        tmpSx.RotateFlip(RotateFlipType.RotateNoneFlipX);
        tmpDx = (Image)img.Clone();
        tmpDw = (Image)img.Clone();
        tmpDw.RotateFlip(RotateFlipType.Rotate90FlipNone);
        tmpUp = (Image)img.Clone();
        tmpUp.RotateFlip(RotateFlipType.Rotate270FlipNone);

    }

    private void Form1_KeyDown(object sender, KeyEventArgs e)
    {
        if (e.KeyCode == Keys.D)
        {
            pictureBox1.Image = tmpDx;
            pictureBox1.Location = new Point(pictureBox1.Location.X + 3, pictureBox1.Location.Y);
            pictureBox1.SendToBack();
        }
        else if (e.KeyCode == Keys.A)
        {
            pictureBox1.Image = tmpSx;
            pictureBox1.Location = new Point(pictureBox1.Location.X - 3, pictureBox1.Location.Y);
            pictureBox1.SendToBack();
        }
        else if (e.KeyCode == Keys.W)
        {
            pictureBox1.Image = tmpUp;
            pictureBox1.Location = new Point(pictureBox1.Location.X, pictureBox1.Location.Y - 3);
            pictureBox1.SendToBack();
        }
        else if (e.KeyCode == Keys.S)
        {
            pictureBox1.Image = tmpDw;
            pictureBox1.Location = new Point(pictureBox1.Location.X, pictureBox1.Location.Y + 3);
            pictureBox1.SendToBack();
        }
        else if(e.KeyCode == Keys.Space)
        {
            Image fire = Image.FromFile(@"c:\users\user\documents\visual studio 2015\Projects\Gioco\Gioco\Resources\494979.gif");
            PictureBox picFire = new PictureBox();
            picFire.Image = fire;
            picFire.Visible = true;
            picFire.BackColor = Color.Transparent;
            panel1.Controls.Add(picFire);
            picFire.BringToFront();
            picFire.Location = new Point(pictureBox1.Location.X + pictureBox1.Width, pictureBox1.Location.Y + pictureBox1.Height / 2);
            picFire.SizeMode = PictureBoxSizeMode.Zoom;



        }
    }
}
}

here is a ScreenShot:

enter image description here

Zohar Peled
  • 79,642
  • 10
  • 69
  • 121
CRK
  • 337
  • 2
  • 10
  • Possible duplicate of [Make Picture boxes transparent, each overlapping the other with a corner?](http://stackoverflow.com/questions/36710701/make-picture-boxes-transparent-each-overlapping-the-other-with-a-corner) – Zohar Peled Jun 10 '16 at 09:35
  • no it isn't a duplicate. – CRK Jun 10 '16 at 10:08
  • Explain: How is this not a duplicate? Since the two pboes are not nested they can overlap with transparency. Either drop pboxes altogether and draw all in the Paint event; use a double-buffered panel or a pbox for this or set a region to the topmost picturebox. which means that its outline must be created in a graphicspath. – TaW Jun 10 '16 at 14:37

0 Answers0