title: How do I stop an MDI child form being dragged outside the edges of the parent?
body: <p><img src="https://i.stack.imgur.com/vlcoT.png" alt="enter image description here"></p>
  
  <p>"People" is a MDI parent Form
  "New" is MDI child Form</p>
  
  <p>How can I stop "New" From being dragged outside "People" edges?</p>
  
  <p>I found that code its working good</p>
  
  <pre><code>    protected override void OnMove(EventArgs e)
      {
          //
          // Get the MDI Client window reference
          //
          MdiClient mdiClient = null;
          foreach (Control ctl in MdiParent.Controls)
          {
              mdiClient = ctl as MdiClient;
              if (mdiClient != null)
                  break;
          }
          //
          // Don't allow moving form outside of MDI client bounds
          //
          if (Left &lt; mdiClient.ClientRectangle.Left)
              Left = mdiClient.ClientRectangle.Left;
          if (Top &lt; mdiClient.ClientRectangle.Top)
              Top = mdiClient.ClientRectangle.Top;
          if (Top + Height &gt; mdiClient.ClientRectangle.Height)
              Top = mdiClient.ClientRectangle.Height - Height;
          if (Left + Width &gt; mdiClient.ClientRectangle.Width)
              Left = mdiClient.ClientRectangle.Width - Width;
          base.OnMove(e);
      }
  </code></pre>