I'm using OpenFileDialog
within a WinForms
application and I can't work out how to get the parent form to show after calling OpenFileDialog.ShowDialog()
.
The functionality is working fully as expected. The problem is that the form stays minimised to the system tray after the OpenFileDialog
has been called, and I can't get it to show in its original position without manually opening the window from the tray.
Constructor
public Simulator()
{
InitializeComponent();
LoadMachine();
...
}
Enclosing method
private void LoadMachine()
{
...
//LoadFile is the OpenFileDialog
LoadFile.InitialDirectory = Application.StartupPath;
if (LoadFile.ShowDialog() != DialogResult.OK) return;
else
{
//some file IO stuff here
}
}
I have tried using this.Focus()
,this.BringToFront()
, FormWindowState.Maximise
and FormWindowState.Normal
amongst others but nothing seems to restore the window. Google and SO have yielded no solutions for me. Any ideas?
Try putting LoadMachine()
in a Shown
event for Simulator
. The ShowDialog
code is being run before the Form is shown.
Example:
private void Simulator_Shown(object sender, EventArgs e)
{
LoadMachine();
}