How can I Change something in a Form1 from a DialogBox?

You can very simply do this. At first change your code(in Form1) that show Form2 to looks like this.

You can very simply do this. At first change your code(in Form1) that show Form2 to looks like this: . ShowDialog(this); or if you don't want form2 to be modal .

Show(this); Next when you got path to image, you can access pictureBox like this ((PictureBox)this.Owner. Controls"pictureBox1"). Image=Image.FromFile(); Assume that you have PictureBox on Form1 with name "pictureBox1.

Basically, expose the value that gets returned in the open file dialog with some property and let the parent form grab it.

In the Program. Cs file you can set any value, either FormOptions to the form's instance . Static void Main() { Application.

EnableVisualStyles(); Application. SetCompatibleTextRenderingDefault(false); var frm = new Form1(); // Add the code to set the picturebox image url Application. Run(frm); } In addition you can add the Constructor to Form1 and pass the parameter via constructor.

Pass one form as a parameter to a constructor of the second form or add a method that passed the reference. After you have the reference to your form you can do whatever you want with the from. Whether to share picture box as a public member is up to you.

However, I would suggest making a public method SetImage() in the first form. Second form would call form1.SetImage(). Update Wait, why do you need to set image from OpenFileDialog, you just need receive fileName from the dialog, and then open the file and load into the form.

Like this: private void button1_Click(object sender, EventArgs e) { using (var dialog = new OpenFileDialog()) { var result = dialog.ShowDialog(); if (result! = DialogResult. OK) return; pictureBox1.

Image = Image. FromFile(dialog. FileName); } } This is code inside of Form1.

Update Here is the basic idea how to access one form from another. Public class MyForm1 : Form { public MyForm1() { InitializeComponent(); } public void SetImage(Image image) { pictureBox1. Image = image; } private void button1_Click(object sender, EventArgs e) { var form2 = new Form2(this); form2.Show(); } } public class MyForm2 : Form { private MyForm1 form1; public MyForm2() { InitializeComponent(); } public MyForm2(MyForm1 form1) { this.

Form1 = form1; } private void button1_Click(object sender, EventArgs e) { form1. SetImage(yourImage); } }.

– Pedrum May 24 at 4:11 This is a good solution to the restated problem... unless you have a requirement to have the picture set from a different form. – Gustavo Mori May 24 at 4:30 I know thi... how can change the picture of the picbox in form1 from form2 ...? – Pedrum May 24 at 4:53 @Pedrum - updated the answer. – Alex Aza May 24 at 5:01.

Ideally, you want to structure your code in a ModelViewController pattern. Then, you simply have a reference in your model to the image in the picture box. When interacting with the OpenFileDialog in Form2, you would call your model adapter interfaces hooked into the views (Form1 and Form2) to change the image being held in the model.In short, you need a callback from the view to the model.

If you don't want to redesign your code to be MVC, simply have a shared object holding the image reference that both Form1 and Form2 receive in their constructors, so they can both modify it.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions