I am trying to use the OpenFileDialog, but its exhibiting some strange behavior that I don't understand.
I have a main form called Dashboard and another form called NewEmployee. When you click on the 'Add New Employee' MenuItem, the 'New Employee' form opens. On this form there is a PictureBox and a Browse button. I have also added an OpenFileDialog. When you click the browse button, the OpenFileDialog opens.
Now, what I want is that, when you select a picture from the OpenFileDialog and click, the picture should populated in the picture box and the OpenFileDialog is dismissed.
What's happening though is that when you select the picture from the OpenFileDialog and click open on the OpenFileDialog, the OpenFileDialog dismisses, but also dismisses my NewEmployee dialog.
Please tell me how I can prevent this.
My code to open the NewEmployee form in the MenItem event is as follows:
private void addStaffToolStripMenuItem_Click(object sender, EventArgs e)
NewEmployeeForm newEmployeeForm = new NewEmployeeForm();
and the code to open the OpenFileDialog and populate the picture box is as follows:
private void browseButton_Click(object sender, EventArgs e)
if (openFileDialog.ShowDialog() == DialogResult.OK)
staffPictureBox.Image = Image.FromFile(openFileDialog.FileName);
string location = openFileDialog.FileName;
Please tell me what am doing wrong.