winform窗体间利用委托传值(一)

前台:在winform窗体Form1放入pictureBox1

后台代码:

namespace 点击小图变成大图
{
public delegate void ClickDelegateHander(string Url);
public partial class Form1 : Form
{
public event ClickDelegateHander ClickEvent; public Form1()
{
InitializeComponent();
}
private void pictureBox1_Click(object sender, EventArgs e)
{
if (ClickEvent != null)
{
ClickEvent(pictureBox1.ImageLocation);
}
}
}
}

前台:在winform窗体Form2放入pictureBox1

后台代码:

namespace 点击小图变成大图
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
Form1 form1 = new Form1();
form1.ClickEvent += new ClickDelegateHander(getUrl);
form1.Show();
} public void getUrl(string Url)
{
this.pictureBox1.ImageLocation = Url;
}
}
}

注意将Form2设置为启动项,

运行后:(如图1-1所示)

winform窗体间利用委托传值(一)

                      图1-1 点击前

点击Form1的图片后Form2里面会出现大的图片(如图1-2所示)

winform窗体间利用委托传值(一)

上一篇:Linux准确获取IP


下一篇:oracle to_char()及to_date()函数使用