可通过如下3种方法,供你参考。
1. 通过设立公共变量访问
从 Form1 传到 Form3
public class Common
{
public static Image MyImage;
}
//Form1
public partial class Form1 : Form
{
private void button1_Click(object sender, EventArgs e)
{
Form3 frm3 = new Form3();
Common.MyImage = this.pictureBox1.Image;
frm3.Show();
}
}
//Form3
public partial class Form3 : Form
{
private void Form3_Load(object sender, EventArgs e)
{
if (Common.MyImage != null)
{
this.pictureBox1.Image = Common.MyImage;
}
}
}
2.通过窗体类的属性传递
从 Form1 传到 Form3
//Form1
public partial class Form1 : Form
{
private void button1_Click(object sender, EventArgs e)
{
Form3 frm3 = new Form3();
frm3.MyImage = this.pictureBox1.Image;
frm3.Show();
}
}
//Form3
public partial class Form3 : Form
{
public Image MyImage { get; set; }
private void Form3_Load(object sender, EventArgs e)
{
if (MyImage != null)
{
this.pictureBox1.Image = MyImage;
}
} }
3.通过委托与事件触发传递
从 Form3 通过事件触发传到 Form1
public delegate void PassInfoDelegate(Image myImage);
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Form3 frm3 = new Form3();
frm3.FireInfoEvent += frm3_FireInfoEvent;
frm3.Show();
}
void frm3_FireInfoEvent(Image myImage)
{
if (this.IsHandleCreated)
{
this.BeginInvoke(new PassInfoDelegate(ShowInfo), new object[] { myImage });
}
}
private void ShowInfo(Image myImage)
{
this.pictureBox1.Image = myImage;
}
}
public partial class Form3 : Form
{
public Form3()
{
InitializeComponent();
}
public event PassInfoDelegate FireInfoEvent;
private void button1_Click(object sender, EventArgs e)
{
PassInfo(this.pictureBox1.Image );
}
private void PassInfo(Image myImage)
{
if (FireInfoEvent != null)
{
FireInfoEvent(myImage);
}
}
}
1. 通过设立公共变量访问
从 Form1 传到 Form3
public class Common
{
public static Image MyImage;
}
//Form1
public partial class Form1 : Form
{
private void button1_Click(object sender, EventArgs e)
{
Form3 frm3 = new Form3();
Common.MyImage = this.pictureBox1.Image;
frm3.Show();
}
}
//Form3
public partial class Form3 : Form
{
private void Form3_Load(object sender, EventArgs e)
{
if (Common.MyImage != null)
{
this.pictureBox1.Image = Common.MyImage;
}
}
}
2.通过窗体类的属性传递
从 Form1 传到 Form3
//Form1
public partial class Form1 : Form
{
private void button1_Click(object sender, EventArgs e)
{
Form3 frm3 = new Form3();
frm3.MyImage = this.pictureBox1.Image;
frm3.Show();
}
}
//Form3
public partial class Form3 : Form
{
public Image MyImage { get; set; }
private void Form3_Load(object sender, EventArgs e)
{
if (MyImage != null)
{
this.pictureBox1.Image = MyImage;
}
} }
3.通过委托与事件触发传递
从 Form3 通过事件触发传到 Form1
public delegate void PassInfoDelegate(Image myImage);
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Form3 frm3 = new Form3();
frm3.FireInfoEvent += frm3_FireInfoEvent;
frm3.Show();
}
void frm3_FireInfoEvent(Image myImage)
{
if (this.IsHandleCreated)
{
this.BeginInvoke(new PassInfoDelegate(ShowInfo), new object[] { myImage });
}
}
private void ShowInfo(Image myImage)
{
this.pictureBox1.Image = myImage;
}
}
public partial class Form3 : Form
{
public Form3()
{
InitializeComponent();
}
public event PassInfoDelegate FireInfoEvent;
private void button1_Click(object sender, EventArgs e)
{
PassInfo(this.pictureBox1.Image );
}
private void PassInfo(Image myImage)
{
if (FireInfoEvent != null)
{
FireInfoEvent(myImage);
}
}
}