title: C# rectangle drawing and screenshot
body: <p>So, let me just start out by showing you the code I have now:</p>
  
  <pre><code>        private void Form1_MouseDown(object sender, MouseEventArgs e)
      {
          currentPos = startPos = e.Location;
          drawing = true;
      }
  
      private void Form1_MouseMove(object sender, MouseEventArgs e)
      {
          currentPos = e.Location;
          //Calculate X Coordinates
          if (e.X &lt; startPos.X)
          {
              CurrentTopLeft.X = e.X;
          }
          else
          {
              CurrentTopLeft.X = startPos.X;
          }
  
          //Calculate Y Coordinates
          if (e.Y &lt; startPos.Y)
          {
              CurrentTopLeft.Y = e.Y;
          }
          else
          {
              CurrentTopLeft.Y = startPos.Y;
          }
  
          if (drawing)
              this.Invalidate();
      }
  
      private void Form1_MouseUp(object sender, MouseEventArgs e)
      {
          if (drawing)
          {
              this.Hide();
              SaveScreen();
          }
      }
  
      private void Form1_Paint(object sender, PaintEventArgs e)
      {
          Color col = Color.FromArgb(75, 100, 100, 100);
          SolidBrush b = new SolidBrush(col);
  
          if (drawing) 
              e.Graphics.FillRectangle(b, getRectangle());
      }
  </code></pre>
  
  <p>My SaveScreen function:</p>
  
  <pre><code>        private void SaveScreen()
          {
  
          ScreenShot.CaptureImage(CurrentTopLeft, Point.Empty, getRectangle());
  
          }
  </code></pre>
  
  <p>The CaptureImage function:</p>
  
  <pre><code>        public static void CaptureImage(Point SourcePoint, Point DestinationPoint, Rectangle SelectionRectangle)
      {
          string FilePath = "temp.jpg";
          using (Bitmap bitmap = new Bitmap(SelectionRectangle.Width, SelectionRectangle.Height))
          {
              using (Graphics g = Graphics.FromImage(bitmap))
              {
                  g.CopyFromScreen(SourcePoint, DestinationPoint, SelectionRectangle.Size);
              }
              bitmap.Save(FilePath, ImageFormat.Jpeg);
          }
  
          string Filename = String.Format("{0:yyyy-M-d-HH-mm-ss}", DateTime.Now) + ".jpg";
          string Server = "";
  
          System.Net.WebClient Client = new System.Net.WebClient();
          Client.Headers.Add("Content-Type", "image/jpeg");
          byte[] result = Client.UploadFile(Server + "upload.php?filename=" + Filename + "", "POST", FilePath);
          string s = System.Text.Encoding.UTF8.GetString(result, 0, result.Length);
  
          Program.mainForm.Notify(Server + Filename);
  
          File.Delete(FilePath);
      }
  </code></pre>
  
  <p>This is just the basic code I have for drawing a rectangle on the screen. When the rectangle is drawn, it takes an image, works perfectly.
  The problem is, that the drawing of the rectangle is not smooth at all. I have enabled doublebuffering and pretty much tried everything, but with no luck.</p>
  
  <p>Also, I would like to grab the current screen, or freeze it, and then be able to draw on that frozen screen, instead of just drawing on top of the active screen if you understand me. How would this be done?</p>
  
  <p>Any help is much appreciated!</p>