title: How create a aligned Rectangle ( TRect ), equal with mouse coordinates?
body: <p>I'm here for know about how create a <code>Rect</code> and <code>Bitmap</code> aligned for the same coordinates sent by  mouse, i already have tried several ways but the  screen capture generated by <code>Bitmap</code> never is equal to area ( image ) sent by mouse and used to make a hole on Form.</p>
  
  <p>For example:</p>
  
  <p><a href="https://i.stack.imgur.com/DL4vV.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DL4vV.jpg" alt="enter image description here"></a></p>
  
  <p>This above is a remote desktop and area selected is where have part of vertical menu.</p>
  
  <p>Then, <code>TBitmap</code> in client side must be this same content.</p>
  
  <p>So, <code>TBitmap</code> in client side must be this same area.</p>
  
  <p>But unfortunately, this is totaly different and image that resulted is in an another position.</p>
  
  <p><a href="https://i.stack.imgur.com/CBwjM.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/CBwjM.png" alt="enter image description here"></a></p>
  
  <p>So, here was my last attempt:</p>
  
  <p><em>This is the way how mouse sents coordinates:</em> <strong>( server side )</strong></p>
  
  <pre><code>type
    TForm2 = class(TForm)
    pbRec: TPaintBox;
    procedure pbRecMouseDown(Sender: TObject; Button: TMouseButton;
        Shift: TShiftState; X, Y: Integer);
      procedure pbRecMouseMove(Sender: TObject; Shift: TShiftState; X,
        Y: Integer);
      procedure pbRecMouseUp(Sender: TObject; Button: TMouseButton;
        Shift: TShiftState; X, Y: Integer);
      procedure pbRecPaint(Sender: TObject);
  
      private
          { Private declarations }
          FSelecting: Boolean;
          FSelection: TRect;
          function ClientToWindow(const P: TPoint): TPoint;
  
      .....
  
      function TForm2.ClientToWindow(const P: TPoint): TPoint;
      begin
        Result := PB1.ClientToScreen(P);
        Dec(Result.X, Left);
        Dec(Result.Y, Top);
      end;
  
      procedure TForm2.pb1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
      begin
        FSelection.Left := X;
        FSelection.Top := Y;
        FSelecting := True;
      end;
  
      procedure TForm2.pb1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
      begin
        if FSelecting then
        begin
          FSelection.Right := X;
          FSelection.Bottom := Y;
          PB1.Invalidate;
        end;
      end;
  
      procedure TForm2.pb1MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
      begin
        FSelecting := False;
        FSelection.Right := X;
        FSelection.Bottom := Y;
        PB1.Invalidate;
  
        FSelection.NormalizeRect;
  
         Socket.SendText(IntToStr(FSelection.Left) + '§' + IntToStr(FSelection.Top) + '§' + IntToStr(X) + '§' + IntToStr(Y));
  
      end;
  
      procedure TForm2.pb1Paint(Sender: TObject);
      begin
        PB1.Canvas.Brush.Color := clRed;
        PB1.Canvas.Rectangle(FSelection);
      end;
  </code></pre>
  
  <hr>
  
  <pre><code>{ And here is how is received:* **( client side ) }
  
   type
        TForm1 = class(TForm)
        CS1: TClientSocket;
        procedure CS1Read(Sender: TObject; Socket: TCustomWinSocket);
  
       private
          { Private declarations }
        public
          { Public declarations }
        end;
  
          procedure TForm1.CS1Read(Sender: TObject; Socket: TCustomWinSocket);
           var
             X1, X2, Y1, Y2: Integer;
             List: TStrings;
             FormRegion, HoleRegion: HRGN;
             Bmp: TBitmap;
             R: TRect;
             StrCommand: String;
  
              begin
               StrCommand := Socket.ReceiveText;
  
               if Pos('§', StrCommand) &gt; 0 then
                begin
  
                  List := TStringList.Create;
                  Bmp :=  TBitmap.Create;
                  try
  
                    ExtractStrings(['§'], [], PChar(StrCommand), List);
  
                   { Coordinates for area sent by mouse in server side }
  
                    X1 := StrToIntDef(List[0], 0);
                    Y1 := StrToIntDef(List[1], 0);
                    X2 := StrToIntDef(List[2], 0);
                    Y2 := StrToIntDef(List[3], 0);
  
               ////////////////////////// THIS IS MY CRITICAL REGION ///////////////////////////
  
                    R := Rect(X1, Y1, X2, Y2);
  
                    Bmp.SetSize(R.Width, R.Height);
  
                    Bmp.Canvas.CopyRect(Rect(0, 0, R.Width, R.Height), Canvas, R);
  
              ///////////////////////////// END OF CRITICAL REGION //////////////////////////////
  
                    Bmp.SaveToFile(GetPathToTestExe+'nil.bmp');
  
                  finally
                    List.Free;
                    Bmp.Free;
                  end;
                end;
  
          end;
  </code></pre>
  
  <p>Any suggestion will welcome.</p>