2 つの重複するPictureBox
es の作成に問題があります。誰もが私に言ったようにコードを書いていますが、いくつか問題があります:
1 つ目: 背景が黒い (なぜ?) 2 つ目: 木が 2 回表示されるのはなぜですか?
編集: 画像http://i48.tinypic.com/2llnfrq.png (スタック オーバーフローに問題がありました)
テスト用のサンプルコードです。
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()
{
}
}