title: C# Custom Close, Minimize and Maximixe buttons
body: <p>I've been trying to create my own program, with custom close maximize and minimize buttons (like in Visual Studio, or Word 2013 etc...(my border style is set to "None")) So what I've been trying to do is creating three buttons. One with the closing option, (works fine) one with the minimize option, (also works fine) and one with the maximize button. alone the maximize button works fine, but i want to have it like standard windows buttons, so that when the form is maximized, it will restore the forms previous state (Normal) which i know can be done with</p>
  
  <pre><code>this.WindowState = FormWindowState.Normal;
  </code></pre>
  
  <p>But it should be with one button if you understand what i mean. What i've tried is making a bool, which's value is set to true when the form is maximized (with an "if" statement) and set to false when the form isn't maximized (else function). Now when the maximize button is clicked the form will maximize and therefore the boolean will be set to true, but when i click again, nothing happens! The other functions like close and minimize works just fine, i even made a "Restore" button, which works just fine!</p>
  
  <p>Any help appreciated, this is my code:</p>
  
  <pre><code>    bool restore;
  
      private void set_Restore()
      {
          {
              if (this.WindowState == FormWindowState.Maximized) //Here the "is" functions is
              {
                  restore = true; //Sets the bool "restore" to true when the windows maximized
              }
              else
              {
                  restore = false; //Sets the bool "restore" to false when the windows isn't maximized
              }
          }
      }
  
      private void MaximizeButton_Click(object sender, EventArgs e)
      {
          {
              if (restore == true)
              {
                  this.WindowState = FormWindowState.Normal; //Restore the forms state
              }
              else
              {
                  this.WindowState = FormWindowState.Maximized; //Maximizes the form
              }
          }
      }
  </code></pre>
  
  <p>Well, i've got three warnings and this is the one i thinks is wrong:</p>
  
  <p>Field 'WindowsFormsApplication2.Form1.restore' is never assigned to, and will always have its default value false.</p>
  
  <p>I think it says that the bool "restore" is never used and will always have it's default value FALSE, which it shouldn't because of my set_Restore when it is maximized.</p>
  
  <p>The other two warnings are:</p>
  
  <p>The variable 'restore' is assigned but its value is never used
  The variable 'restore' is assigned but its value is never used</p>
  
  <p>Thank you in advance.</p>