Our application has the following requirement: If the application is running and I start the application again, the first instance has to be activated instead to open a new instance.
To realize this, in the main routine I check if there is already a running instance. If yes I use following command to bring in front the first instance:
Microsoft.VisualBasic.Interaction.AppActivate(appIdentifier);
Until now all works as expected. The only problem with this solution is that in case of the first instance is minimized, by start the application again the first instance will be active, but not visible (still minimized)
And this is my question. How can I go back to the last WindowState by activating the instance. My solution was, to subscribe for the Form.Activated event and execute following code in the eventhandler method:
if (MyForm.WindowState == FormWindowState.Minimized)
{
MyForm.WindowState = FormWindowState.Normal;
}
But with this solution I have the problem, that if the application was in maximized-state before minimizing the application do not goes back to it after activate it.
Has anybody an idea how I can solve this? is there a chance to get the last windowState?
Thanks in advance for your help!