C#移动透明PictureBox

时间:2016-06-10 09:16:17

标签: c# picturebox transparent

当picbox1通过picbox2时,我试着让picbox2背面颜色变为透明。这是我的代码

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;



        }
    }
}
}

这是一个ScreenShot:

enter image description here

0 个答案:

没有答案