[C#] 纯文本查看 复制代码
[/b][/color][/size]
public partial class Form1 : Form
{ /// <summary>
/// 定义一个显示图片的委托
/// </summary>
/// <param name="img"></param>
public delegate void ShowPicture(Image img);
/// <summary>
/// 定义委托类型的变量
/// </summary>
public static ShowPicture OnPicSaved;
public Form1()
{
InitializeComponent();
OnPicSaved = ShowIt;//给变量赋值
}
/// <summary>
/// 修改窗体背景颜色的方法
/// </summary>
/// <param name="img"></param>
private void ShowIt(Image img)
{
this.BackgroundImage = img;
}
}
Form2中的代码如下:
public Form2()
{
InitializeComponent();
Form1 frm1 = new Form1();
frm1.Show();//显示Form1窗体
}
private void btnSelImg_Click(object sender, EventArgs e)
{
if (null == openFileDialog1.ShowDialog())//打开对话框
{
return;
}
//让窗体中的PictureBox显示图片
picBoxShow.Image = Image.FromFile(openFileDialog1.FileName);
//调用Form1中的委托,更改Form1背景颜色
Form1.OnPicSaved(picBoxShow.Image);
}
} [size=4][color=#ff0000][b]