title: Draw a rectangle
body: <p>For some reason the rectangle doesn't show up when I run the program. But the code runs without any errors. What am I doing wrong?</p>
  
  <p>(I am using csc.exe to compile the code, and I'm writing it in notepad++)</p>
  
  <p>Drawing code:</p>
  
  <pre><code>Graphics g = myform.CreateGraphics();
  Pen selPen = new Pen(Color.Blue);
  g.DrawRectangle(selPen, 10, 10, 50, 50);
  g.Dispose();
  </code></pre>
  
  <p>Complete Code:</p>
  
  <pre><code>using System;
  using System.Windows.Forms;
  using System.Drawing;
  
  public class Hello1
  {
  
      public static void Main()
      {
  
          Form myform = new Form();
  
          myform.Text = "Main Window";
          myform.Size = new Size(640, 400);
          myform.FormBorderStyle = FormBorderStyle.FixedDialog;
          myform.StartPosition = FormStartPosition.CenterScreen;
  
  
          Graphics g = myform.CreateGraphics();
          Pen selPen = new Pen(Color.Blue);
          g.DrawRectangle(selPen, 10, 10, 50, 50);
          g.Dispose();
  
          myform.ShowDialog();
  
      }
  
  }
  </code></pre>