title: C# Panel move and resize object
body: <p>I have a problem with draw in panel.</p>
  
  <p>I wrote a code to move and resize my object in a panel,
  but when i move or resize my object you can see what happens for panel.</p>
  
  <p><a href="https://i.stack.imgur.com/tExXU.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/tExXU.jpg" alt="My Application Screenshot"></a></p>
  
  <p>And here is my code :</p>
  
  <pre><code>    private void DrawControlBorder(object sender)
      {
          Control control = (Control)sender;
          //define the border to be drawn, it will be offset by DRAG_HANDLE_SIZE / 2
          //around the control, so when the drag handles are drawn they will be seem
          //connected in the middle.
          Rectangle Border = new Rectangle(
              new Point(control.Location.X - DRAG_HANDLE_SIZE / 2,
                  control.Location.Y - DRAG_HANDLE_SIZE / 2),
              new Size(control.Size.Width + DRAG_HANDLE_SIZE,
                  control.Size.Height + DRAG_HANDLE_SIZE));
          //define the 8 drag handles, that has the size of DRAG_HANDLE_SIZE
          Rectangle NW = new Rectangle(
              new Point(control.Location.X - DRAG_HANDLE_SIZE,
                  control.Location.Y - DRAG_HANDLE_SIZE),
              new Size(DRAG_HANDLE_SIZE, DRAG_HANDLE_SIZE));
          Rectangle N = new Rectangle(
              new Point(control.Location.X + control.Width / 2 - DRAG_HANDLE_SIZE / 2,
                  control.Location.Y - DRAG_HANDLE_SIZE),
              new Size(DRAG_HANDLE_SIZE, DRAG_HANDLE_SIZE));
          Rectangle NE = new Rectangle(
              new Point(control.Location.X + control.Width,
                  control.Location.Y - DRAG_HANDLE_SIZE),
              new Size(DRAG_HANDLE_SIZE, DRAG_HANDLE_SIZE));
          Rectangle W = new Rectangle(
              new Point(control.Location.X - DRAG_HANDLE_SIZE,
                  control.Location.Y + control.Height / 2 - DRAG_HANDLE_SIZE / 2),
              new Size(DRAG_HANDLE_SIZE, DRAG_HANDLE_SIZE));
          Rectangle E = new Rectangle(
              new Point(control.Location.X + control.Width,
                  control.Location.Y + control.Height / 2 - DRAG_HANDLE_SIZE / 2),
              new Size(DRAG_HANDLE_SIZE, DRAG_HANDLE_SIZE));
          Rectangle SW = new Rectangle(
              new Point(control.Location.X - DRAG_HANDLE_SIZE,
                  control.Location.Y + control.Height),
              new Size(DRAG_HANDLE_SIZE, DRAG_HANDLE_SIZE));
          Rectangle S = new Rectangle(
              new Point(control.Location.X + control.Width / 2 - DRAG_HANDLE_SIZE / 2,
                  control.Location.Y + control.Height),
              new Size(DRAG_HANDLE_SIZE, DRAG_HANDLE_SIZE));
          Rectangle SE = new Rectangle(
              new Point(control.Location.X + control.Width,
                  control.Location.Y + control.Height),
              new Size(DRAG_HANDLE_SIZE, DRAG_HANDLE_SIZE));
  
  
          //get the form graphic
          Graphics g = panelView.CreateGraphics();
  
          //draw the border and drag handles
          ControlPaint.DrawBorder(g, Border, Color.Gray, ButtonBorderStyle.Dotted);
          ControlPaint.DrawGrabHandle(g, NW, true, true);
          ControlPaint.DrawGrabHandle(g, N, true, true);
          ControlPaint.DrawGrabHandle(g, NE, true, true);
          ControlPaint.DrawGrabHandle(g, W, true, true);
          ControlPaint.DrawGrabHandle(g, E, true, true);
          ControlPaint.DrawGrabHandle(g, SW, true, true);
          ControlPaint.DrawGrabHandle(g, S, true, true);
          ControlPaint.DrawGrabHandle(g, SE, true, true);
  
          g.Dispose();
          //graphPanel.Dispose();
          //bitmap.Dispose();
      }
  </code></pre>
  
  <p>Anybody can help me?</p>
  
  <p>tnx</p>