我制作了一个程序,我需要在Form1中更改我的Picturebox。这需要以第二种形式(Form2)
进行窗体2:
private void btnBrowseFirstAd_Click(object sender, EventArgs e)
{
OpenFileDialog OFD = new OpenFileDialog();
if (OFD.ShowDialog() == DialogResult.OK)
{
tbFirstAdBlock.Text = OFD.FileName;
}
}
private void btnChangeFirstAd_Click(object sender, EventArgs e)
{
Form1 Screen = new Form1();
Screen.changePB(tbFirstAdBlock.Text);
}
Form1中
public void changePB(string PBLocation)
{
pbAddOne.Image = Image.FromFile(PBLocation);
}
可悲的是,图片框并没有改变。
答案 0 :(得分:0)
在Form2中,您需要链接到Form1:
class Form2
{
public Form1 form1;
.....
private void btnChangeFirstAd_Click(object sender, EventArgs e)
{
form1.changePB(tbFirstAdBlock.Text);
form1.Refresh();
}
}
...
void Main()
{
Form1 Screen =new Form1();
Form2 Screen1 =new Form2();
Screen1.form1=Screen;
}
...