How can I restore the main window after minimize the main window? Thanks!

 

I use the code below to make the program ran only one time, I hope the main window can be restored automatically when you try to launch the program for the sencond time.


  [STAThread]
  static void Main()
  {
   bool createNew;
   Mutex m=new  Mutex(true,"SuperCoolPhotoOnlyOneTime",out createNew);
   if (createNew)
   {
    Application.Run(new FormMain());
    m.ReleaseMutex();
   }
                        else
                        {
                               //if the state of the main window is minimum,I hope the main main can be restored automatically!
                        }
   
  }

 




Answer this question

How can I restore the main window after minimize the main window? Thanks!

  • changshen

    Well I've tested it and it does compile, so you are doing something wrong.  How about, instead of copying and pasting code, you use the principle and write your own code.  That way you can let Intellisense guide you.  Go to the properties window for your form and click the lightning bolt button at the top to display all the form's events.  Then, double-click the Resize event to generate an event handler for the event.  In that event handler, start typing code that resembles what has been provided and let Intellisense guide you.  If you want Intellisense for form members then you need to use "this" to reference the form itself.  If you follow this advice you should end up with the following code:


            private void Form1_Resize(object sender, EventArgs e)
            {
                if (this.WindowState == FormWindowState.Minimized)
                {
                    this.WindowState = FormWindowState.Normal;               
                }
            }

     





  • Dejan

    I'm sorry, i have tested your code, it's wrong, can't be compiled

  • PabloFe

    You can use the following code to bring a minimised window into Normal state

    if( WindowState == FormWindowState.Minimized )

    WindowState = FormWindowState.Normal ;


    Regards,
    Saurabh Nandu
    www.MasterCSharp.com
    www.AksTech.com



  • Sanjay_ati

    If the code doesn't do what want then say so.  It did compile and it did exactly what it implied that it did.  If you want people to help you then I suggest you do not shout at them ever again, which your colouring of the word "forever" comes across as.  I suggest you do a search for "single instance" on MSDN and elsewhere.

  • David Jones

    I hope the main window can be restored automatically when you try to launch the program for the sencond time.

    What you write will make the main window being Normal window forever!

  • How can I restore the main window after minimize the main window? Thanks!