openFileDialog

E

e-mid

why does not openFileDialog have closed event?

i want to do something; as soon as the dialog closes. is there a way to do
this?
 
S

Shakir Hussain

Try this

if(openFileDialog1.ShowDialog() == DialogResult.OK)
{
MessageBox.Show(""user has pressed Open button");
}
else
{
MessageBox.Show("User has pressed cancel button or X button to
close");
}
 
C

Christopher Kimbell

One reason for there not being a close event is that the dialog can only be
shown in modal mode,
the code will wait until the ShowDialog() returns with a DialogResult value.
You can use this value to determine an apropriate action based on how the
Dialog was closed.

Chris
 
E

e-mid

in fact, i want to open another modal dialog according to file chosen. after
i get dialogResult ; i keep filename. but i have to wait openfiledialog
being closed to open a modal form.

there seems no way to that?
 
C

Christopher Kimbell

I' not quire sure what you want to achieve.
Since the OpenFileDialog is modal, you can't get access to the selected
filename before the dialog has closed.
In the code posted by Shakir, replace the MessageBox code with some code
that launches your other form.
Before launching it, get whatever data you need from the OpenFileDialog
object.


Chris
 
E

e-mid

when i open my new modal form after i get dialog.ok result, openFileDialog
window is open too. therefore i asked for openFileDialog closed event or
some other way to do.
 
J

John Wood

The OpenFileDialog shows modally, and when OK or Cancel is clicked the
dialog closes and you can do whatever you want. If you see that the dialog
is still visible, then perhaps the screen has not yet had a chance to paint
itself. You could get around this with an Application.DoEvents() call right
after the ShowDialog function returns.
 
S

Shakir Hussain

e-mid,

after clicking "Open" or "Cancel" button in the OpenFileDialog, it will
close for sure.

I believe, you were able to see the dialog box still(like it exists), which
may be due to painting problem.

After closing the OpenFileDialog call

Form1.Refresh();
Form2.ShowDialog();

Refresh method will invalidate the whole client area.

Shak.
(Houston)
 
E

e-mid

thnkz, it is ok now...


Shakir Hussain said:
e-mid,

after clicking "Open" or "Cancel" button in the OpenFileDialog, it will
close for sure.

I believe, you were able to see the dialog box still(like it exists), which
may be due to painting problem.

After closing the OpenFileDialog call

Form1.Refresh();
Form2.ShowDialog();

Refresh method will invalidate the whole client area.

Shak.
(Houston)
 

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