[英]Pass the background image of a form to another through a button?
How i can do what, the background image of a form1, be equal to the background image of a form2 through a button? 我怎么做,form1的背景图像,通过按钮等于form2的背景图像?
This is my button with the image in the form1 (Pressing this button change the background of form1.) 这是我的按钮,其中包含form1中的图像(按此按钮可更改form1的背景。)
private void button1_Click (object sender, EventArgs e)
{
this.BackgroundImage = Properties.Resources._02_blue
}
I want what this image be the background image of the form2 Examples will serve me. 我想要这个图像是form2的背景图像2示例将为我服务。 Thanks. 谢谢。
Am I missing something? 我错过了什么吗?
form2.BackgroundImage = form1.BackgroundImage;
Where form2
is instance of Form2
and form1
is instance of form1
当form2
是实例Form2
和form1
的实例form1
just use a static property on Form1 and retrieve it from form2 只需在Form1上使用静态属性并从form2中检索它
public static Image Form1Background
{
get ; set;
}
//to set in your Form1 //在Form1中设置
Form1Background= this.BackgroundImage = Properties.Resources._02_blue;
// from others form //来自其他人的形式
form2.BackgroundImage= Form1.Form1Background
One approach would be to inject it into Form2
. 一种方法是将其注入Form2
。 Build a new constructor: 构建一个新的构造函数:
public Form2(Image bg) { this.BackgroundImage = bg; }
and then use that when building it: 然后在构建它时使用它:
var f = new Form2(this.BackgroundImage);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.