Need help with OpenFileDialog

D

Durango2008

Hello I am reposting since my initial post was not appropriate, hope I was
not too offensive.

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 :)
 
G

Guest

Hello I am reposting since my initial post was not appropriate, hope I was
not too offensive.

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 :)

microsoft.public.dotnet.framework.windowsforms
 

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

Members online

No members online now.

Forum statistics

Threads
474,039
Messages
2,570,376
Members
47,029
Latest member
EmiliaSton

Latest Threads

Top