title: Why is the windows forms auto-resizing the height when im trying to center a usercontrol on it?(C#)
body: <p>So basically what I'm trying to do is center a PictureBox control on an empty windows form with specified size, given that the size of the form is actually always bigger than that of my control.However, whenever I'm am trying to center it(what i mean is actually have equal distances from the margins of the form,equal distance for the width and equal distances for the height since the height and width aren't equal in my code.Ex: width=700 and Height=500), between the bottom of my form and the bottom of my control there is less space than between the top of the form and the top of the control.</p>
  
  <p>Here is a picture to illustrate the issue:
  <a href="https://i.stack.imgur.com/URozj.png" rel="nofollow noreferrer">https://i.stack.imgur.com/URozj.png</a></p>
  
  <p>Here is the entire code,please don't critic the reasoning behind how it's made, i would just like to know why the form resizes or puts my control at the bottom if i add it to the form.</p>
  
  <pre><code>public static class Engine
  {
      public static Graphics G;
      public static Bitmap Map;
      public static PictureBox Canvas;
  
      public static void Initialize_mystuff(int width, int height)
      {
          Map = new Bitmap(width, height);
          G = Graphics.FromImage(Map);
          Canvas = new PictureBox();
          Canvas.Size = new Size(Map.Width, Map.Height);
          Canvas.BorderStyle = BorderStyle.FixedSingle;
          Canvas.BackgroundImage = Map;
      }
  
      public static Point CenterUControl(Size Parent, Size Child)
      {
          return new Point(Parent.Width / 2 - Child.Width / 2, Parent.Height / 2 - Child.Height / 2);
      }
  
  }
  </code></pre>
  
  <p>So above is the code for where I initialize everything I'm working with and also have a function to return me the location of where the object should be centered relative to it's parent.And below is the code where I call the initialize and center functions in the forms constructor.</p>
  
  <pre><code>public partial class Form1 : Form
  {
      public Form1()
      {
          InitializeComponent();
          this.SuspendLayout();
          Engine.Initialize_mystuff(400,400);
          this.Controls.Add(Engine.Canvas);
          this.Size = new Size(700, 500);
          Engine.Canvas.Location=Engine.CenterUControl(this.Size, Engine.Canvas.Size);
          this.ResumeLayout();
      }
  
      private void Form1_Load(object sender, EventArgs e)
      {
  
      }
  }
  </code></pre>
  
  <p>Also the AutoSize property of the form is set to false.</p>