Relates to my previous question.
In my previous question I asked why my dialogs seem to be opening behind other windows. (Other windows not necessarily belonging to my program, e.g. Excel, Windows Explorer, etc.)
I was told to use the overloaded ShowDialog() and pass the parent as a parameter.
That’s fine, and I’ve replaced all the ShowDialog()s with the overload.
However I still had the same problem here:
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
OpenFileDialog ofd = new OpenFileDialog();
ofd.ShowDialog(); // First dialog
// Do some stuff here...
SaveFileDialog sfd = new SaveFileDialog();
sfd.ShowDialog(); // Second dialog;
}
}
In this example (don’t comment on the code – I just wrote it up as a simple example), the user double-clicks the executable with several windows on their screen. The OFD appears on top, and the SFD appears underneath everything.
I usually have this sort of OFD/SFD set up in my simple programs which accept CSV or XLS files and do some simple processing of them. In this case, I put the OFD code in the static Main() method and load the dialog if no parameters were passed to the exe.
Modal Dialog boxes aren’t meant to be used this way, although there’s nothing stopping you from doing it anyway.
You must have an
Application.Runas shsmith said.For the simple example you gave in the question I would have a small window show up with a progress bar and/or rolling log status text.