OpenFileDialog FileOk event does not get called.


D

Durango2008

Hello I created a simple form with an OpenFileDialog object that allows me
to browse the FS

and select a file from it.
However when I do select a file and press Open the FileOk event does not get
called.
Here is the code I have right now.

public partial class Form1 : Form
{
private string imgFile = null;
private const string Default_Path = "C:\\";
OpenFileDialog ofd = new OpenFileDialog();
public Form1()
{
InitializeComponent();
InitializeOpenFileDialog();
}

private void InitializeOpenFileDialog()
{
ofd.Filter =
"Images (*.BMP;*.JPG;*.GIF)|*.BMP;*.JPG;*.GIF|" +
"All files (*.*)|*.*";
ofd.InitialDirectory = Default_Path;
ofd.Title = "My Image Browser";
}
private void button1_Click(object sender, EventArgs e)
{
string imagePath = null;
if (imageFileTB.Text.Length > 0)
imagePath = imageFileTB.Text;
if (Directory.Exists(imagePath))
ofd.InitialDirectory = imagePath;
ofd.ShowDialog();
}

private void openFileDialog1_FileOk_1(object sender, CancelEventArgs
e)
{
this.Activate();
imageFileTB.Text = ofd.FileName;
MessageBox.Show("**** you " + ofd.FileName);
}
}

I have setup the OpenFileDialog FileOk event to call the
openFileDialog1_FileOk_1 method.
I looked up an example on MSDN and that was not working either. I am sure I
may be

forgetting something simple.
Anyway, I appreciate any help on this :)
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top