1、采用“1”个参数的重载Form2参考代码:Form2的代码: public Form2()
{
InitializeComponent();
}
public Form2(Form form)
{
f = form;
InitializeComponent();
}
private Form f;2、调用打开Form2的位置作如下修改:
Form2 f = new Form2(this);//把Form1传到Form2去
f.ShowDialog();3、combobox的选择事件里: f.BackgroundImage = Image.FromFile("D:\\Cypress.jpg");
可以在Form1中设置一个public函数,用了修改背景图片。Form2通过访问该public函数来进行修改。相关实例已经在你有关combox传回索引的帖子中做了说明。
this.BackgroundImage = this.imageList1.Images[0];你在combobox改变选项后的那个事件里,写上面这句就可以了。你加个imageList1控件,里面加一些图片,然后通过它的属性Images改变索引就能确定哪一张图片了。
在new form2时 Form2 frm = new Form2()frm.show(this); // this为form1在form2的事件里写上if (null != this.Parent){ ( (Form)this.Parent).backgroundimage = this.imageList1.Images[0];}