省事写法
Form1.cs
程序代码:
using System.Drawing;
using System.Windows.Forms;
namespace Test1
{
public partial class Form1 : Form
{
public static PictureBox pb;
public Form1()
{
InitializeComponent();
this.StartPosition = FormStartPosition.CenterScreen;
pb = new PictureBox()
{
Size = new Size(250, 250),
Location = new Point(10, 10),
Image = Image.FromFile("3.png"),
};
this.Controls.Add(pb);
Load += (s, e) => {
new Form2().Show();
};
}
}
}
Form2.cs
程序代码:
using System.Drawing;
using System.Windows.Forms;
namespace Test1
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
this.StartPosition = FormStartPosition.Manual;
this.Location = new Point(0, 0);
Button btn = new Button()
{
Text = "change!",
Location = new Point(10, 10)
};
btn.Click += (s, e) =>
{
Form1.pb.Image = Image.FromFile("11.gif");
};
this.Controls.Add(btn);
}
}
}