C# 设置重叠的两个图片框
我无法创建两个重叠的C# 设置重叠的两个图片框,c#,image,picturebox,overlapping,C#,Image,Picturebox,Overlapping,我无法创建两个重叠的PictureBoxes。我像每个人告诉我的那样编写代码,但我有一些问题: 第一:背景是黑色的(为什么?) 第二:为什么树出现两次 编辑: 映像(堆栈溢出有问题) 这是用于测试的示例代码 public partial class Form1 : Form { public Form1() { InitializeComponent(); this.AllowTransparency = true; MyPic
PictureBox
es。我像每个人告诉我的那样编写代码,但我有一些问题:
第一:背景是黑色的(为什么?)
第二:为什么树出现两次
编辑:
映像(堆栈溢出有问题)
这是用于测试的示例代码
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.AllowTransparency = true;
MyPictureBox pb1 = new MyPictureBox();
MyPictureBox pb2 = new MyPictureBox();
pb1.Size = new Size(64, 64);
pb1.Location = new Point(20, 20);
pb1.BackColor = Color.Transparent;
//pb1.SizeMode = PictureBoxSizeMode.Zoom;
pb2.Size = new Size(64, 64);
pb2.Location = new Point(52, 20);
pb2.BackColor = Color.Transparent;
pb1.Image = Image.FromFile("D:\\...\\Graphics\\Grounds\\woda1.png");
pb2.Image = Image.FromFile("D:\\...\\Graphics\\Objects\\tree1.png");
panel1.Controls.Add(pb2);
panel1.Controls.Add(pb1);
}
private void panel1_Paint(object sender, PaintEventArgs e)
{
}
}
class MyPanel : Panel
{
protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.ExStyle |= 0x20;
return cp;
}
}
protected override void OnPaintBackground(PaintEventArgs e)
{
// Do Nothing
}
public MyPanel()
{
}
}
class MyPictureBox : PictureBox
{
protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.ExStyle |= 0x20;
return cp;
}
}
protected override void OnPaintBackground(PaintEventArgs e)
{
// Do Nothing
}
public MyPictureBox()
{
}
}
你能提供你表格的截图吗?Thx.你说那棵树出现了两次,但我们真的不知道你的确切意思。显示一个图像,或者别的什么。我很快就尝试了(用你的代码),效果很好…我上传图像有问题,我在其他电脑上尝试过,可能是堆栈溢出问题。如果你是C#,你只会看到一棵树。抱歉,无法容纳:)