Wrox Programmer Forums
|
BOOK: Beginning Visual C# 2010
This is the forum to discuss the Wrox book Beginning Visual C# 2010 by Karli Watson, Christian Nagel, Jacob Hammer Pedersen, Jon D. Reid, Morgan Skinner, ; ISBN: 9780470502266
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning Visual C# 2010 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 2nd, 2012, 06:32 PM
Authorized User
 
Join Date: Jan 2011
Posts: 41
Thanks: 0
Thanked 1 Time in 1 Post
Default OpenFileDialog

Hi,

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:
Code:
private void addStaffToolStripMenuItem_Click(object sender, EventArgs e)
{
      NewEmployeeForm newEmployeeForm = new NewEmployeeForm();
      newEmployeeForm.ShowDialog();
}
and the code to open the OpenFileDialog and populate the picture box is as follows:

Code:
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.

Thanks.
 
Old October 24th, 2012, 11:04 AM
Wrox Author
 
Join Date: Sep 2010
Posts: 175
Thanks: 3
Thanked 53 Times in 53 Posts
Default

this shouldn't be the case. Can you check the DialogResult property of the browse button? Probably it is set to a DialogResult, and thus the dialog closes.
__________________
Christian
CN innovation
Visit my blog at: csharp.christiannagel.com
Follow me on twitter: @christiannagel





Similar Threads
Thread Thread Starter Forum Replies Last Post
OpenFileDialog using vba vrocs Access VBA 0 May 4th, 2010 05:34 AM
OpenFileDialog on .NET Compact Framework yukijocelyn C# 2005 0 July 4th, 2008 11:35 PM
OpenFileDialog using vba Suomi Access VBA 9 June 13th, 2007 01:07 PM
Using the OpenFileDialog johno BOOK: Beginning VB.NET 2nd Edition/Beginning VB.NET 2003 7 May 28th, 2007 02:57 AM
OpenfileDialog class krellee General .NET 1 September 14th, 2005 01:24 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.