title: Defined max. and min. size is somewhere overridden
body: <p>I am currently developing a <code>gui</code> which content is defined in a specific <code>xml</code> file. I have so called <code>Widgets</code>. These widgets have it's own implemented logic plus have a defined width and height. Both, the <code>minimum</code> and <code>maximum size</code>, are fix and cannot be changed. A Widget is a <code>UserControl</code>.</p>
  
  <p>Screenshot showing the fix max. and min. size:</p>
  
  <p><a href="https://i.stack.imgur.com/oY01p.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/oY01p.png" alt="enter image description here"></a></p>
  
  <p>For an right now unknown reason the size is during runtime different. As seen on the following screenshot:
  <a href="https://i.stack.imgur.com/5gQNC.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/5gQNC.png" alt="enter image description here"></a></p>
  
  <p>Beside the designer file of the <code>SingleplayerWidget</code> my own source code, of the SingeplayerWidget, is following:</p>
  
  <pre><code>using System;
  using System.Drawing;
  using System.Windows.Forms;
  using Racetrack.Controller;
  
  namespace Racetrack.View.Widgets
  {
  public partial class SingleplayerWidget : UserControl
  {
      private GameController Controller;
  
      public SingleplayerWidget()
      {
          InitializeComponent();
          this.extendedTextBoxPlayername.SetPlaceholder("Choose a playername");
      }
  
      public SingleplayerWidget(GameController controller)
      {
          InitializeComponent();
          this.Controller = controller;
          this.extendedTextBoxPlayername.SetPlaceholder("Choose a playername");
  
          this.colorDialogCarColor = new ColorDialog();
          this.colorDialogCarColor.Color = Color.Black;
          this.panelCarColor.BackColor = this.colorDialogCarColor.Color;
      }
  
      private void menuButtonChangeCarColor_Click(object sender, EventArgs e)
      {
          this.colorDialogCarColor.ShowDialog();
          this.panelCarColor.BackColor = this.colorDialogCarColor.Color;
      }
  }
  }
  </code></pre>
  
  <p>And this is the designer source code:</p>
  
  <pre><code>namespace Racetrack.View.Widgets
  {
  partial class SingleplayerWidget
  {
      /// &lt;summary&gt; 
      /// Required designer variable.
      /// &lt;/summary&gt;
      private System.ComponentModel.IContainer components = null;
  
      /// &lt;summary&gt; 
      /// Clean up any resources being used.
      /// &lt;/summary&gt;
      /// &lt;param name="disposing"&gt;true if managed resources should be disposed; otherwise, false.&lt;/param&gt;
      protected override void Dispose(bool disposing)
      {
          if (disposing &amp;&amp; (components != null))
          {
              components.Dispose();
          }
          base.Dispose(disposing);
      }
  
      #region Component Designer generated code
  
      /// &lt;summary&gt; 
      /// Required method for Designer support - do not modify 
      /// the contents of this method with the code editor.
      /// &lt;/summary&gt;
      private void InitializeComponent()
      {
          this.labelWidgetHeadline = new System.Windows.Forms.Label();
          this.labelPlayername = new System.Windows.Forms.Label();
          this.colorDialogCarColor = new System.Windows.Forms.ColorDialog();
          this.labelCarColor = new System.Windows.Forms.Label();
          this.panelCarColor = new System.Windows.Forms.Panel();
          this.menuButtonChangeCarColor = new Racetrack.View.Forms.MenuButton();
          this.extendedTextBoxPlayername = new Racetrack.View.Forms.ExtendedTextBox();
          this.SuspendLayout();
          // 
          // labelWidgetHeadline
          // 
          this.labelWidgetHeadline.Anchor = System.Windows.Forms.AnchorStyles.None;
          this.labelWidgetHeadline.AutoSize = true;
          this.labelWidgetHeadline.Font = new System.Drawing.Font("Microsoft Sans Serif", 13.8F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
          this.labelWidgetHeadline.Location = new System.Drawing.Point(14, 8);
          this.labelWidgetHeadline.Name = "labelWidgetHeadline";
          this.labelWidgetHeadline.Size = new System.Drawing.Size(188, 29);
          this.labelWidgetHeadline.TabIndex = 2;
          this.labelWidgetHeadline.Text = "Your Character";
          // 
          // labelPlayername
          // 
          this.labelPlayername.Anchor = System.Windows.Forms.AnchorStyles.None;
          this.labelPlayername.AutoSize = true;
          this.labelPlayername.Location = new System.Drawing.Point(17, 58);
          this.labelPlayername.Name = "labelPlayername";
          this.labelPlayername.Size = new System.Drawing.Size(87, 17);
          this.labelPlayername.TabIndex = 3;
          this.labelPlayername.Text = "Playername:";
          // 
          // labelCarColor
          // 
          this.labelCarColor.Anchor = System.Windows.Forms.AnchorStyles.None;
          this.labelCarColor.AutoSize = true;
          this.labelCarColor.Location = new System.Drawing.Point(17, 120);
          this.labelCarColor.Name = "labelCarColor";
          this.labelCarColor.Size = new System.Drawing.Size(69, 17);
          this.labelCarColor.TabIndex = 5;
          this.labelCarColor.Text = "Car color:";
          // 
          // panelCarColor
          // 
          this.panelCarColor.Anchor = System.Windows.Forms.AnchorStyles.None;
          this.panelCarColor.Location = new System.Drawing.Point(20, 140);
          this.panelCarColor.Name = "panelCarColor";
          this.panelCarColor.Size = new System.Drawing.Size(80, 37);
          this.panelCarColor.TabIndex = 8;
          // 
          // menuButtonChangeCarColor
          // 
          this.menuButtonChangeCarColor.Anchor = System.Windows.Forms.AnchorStyles.None;
          this.menuButtonChangeCarColor.BackColor = System.Drawing.SystemColors.GradientInactiveCaption;
          this.menuButtonChangeCarColor.FlatAppearance.BorderSize = 0;
          this.menuButtonChangeCarColor.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
          this.menuButtonChangeCarColor.Location = new System.Drawing.Point(119, 140);
          this.menuButtonChangeCarColor.Name = "menuButtonChangeCarColor";
          this.menuButtonChangeCarColor.Size = new System.Drawing.Size(75, 37);
          this.menuButtonChangeCarColor.TabIndex = 9;
          this.menuButtonChangeCarColor.Text = "change";
          this.menuButtonChangeCarColor.UseVisualStyleBackColor = false;
          this.menuButtonChangeCarColor.Click += new System.EventHandler(this.menuButtonChangeCarColor_Click);
          // 
          // extendedTextBoxPlayername
          // 
          this.extendedTextBoxPlayername.Anchor = System.Windows.Forms.AnchorStyles.None;
          this.extendedTextBoxPlayername.Location = new System.Drawing.Point(19, 83);
          this.extendedTextBoxPlayername.Name = "extendedTextBoxPlayername";
          this.extendedTextBoxPlayername.Size = new System.Drawing.Size(180, 22);
          this.extendedTextBoxPlayername.TabIndex = 4;
          // 
          // SingleplayerWidget
          // 
          this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);
          this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
          this.BackColor = System.Drawing.SystemColors.Window;
          this.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
          this.Controls.Add(this.menuButtonChangeCarColor);
          this.Controls.Add(this.panelCarColor);
          this.Controls.Add(this.labelCarColor);
          this.Controls.Add(this.extendedTextBoxPlayername);
          this.Controls.Add(this.labelPlayername);
          this.Controls.Add(this.labelWidgetHeadline);
          this.MaximumSize = new System.Drawing.Size(225, 325);
          this.MinimumSize = new System.Drawing.Size(225, 325);
          this.Name = "SingleplayerWidget";
          this.Size = new System.Drawing.Size(225, 325);
          this.ResumeLayout(false);
          this.PerformLayout();
  
      }
  
      #endregion
  
      private System.Windows.Forms.Label labelWidgetHeadline;
      private System.Windows.Forms.Label labelPlayername;
      private System.Windows.Forms.ColorDialog colorDialogCarColor;
      private Forms.ExtendedTextBox extendedTextBoxPlayername;
      private System.Windows.Forms.Label labelCarColor;
      private System.Windows.Forms.Panel panelCarColor;
      private Forms.MenuButton menuButtonChangeCarColor;
  }
  }
  </code></pre>
  
  <p>My <code>GameConfigurationView</code> has <code>AutoSize = False</code>. My <code>Widgets</code> have the same property value and the source code (I exclude the designer file as of the question length). <em>I know the source code needs to be cleaned up later.</em></p>
  
  <p>As you can see the following source code I assign the size as well, when initializing a new widget. This does not work either.</p>
  
  <pre><code>using System.Drawing;
  using System.Windows.Forms;
  using System.Xml;
  using Racetrack.Controller;
  using Racetrack.View.Widgets;
  
  namespace Racetrack.View
  {
  public partial class GameConfigurationView : Form
  {
      protected GameController Controller { get; set; }
      protected MapSelectionWidget MapSelectionWidget { get; set; }
      protected SingleplayerWidget SingleplayerWidget { get; set; }
  
      protected Point GuiBuilderNextLocation { get; set; }
      protected Size GuiBuilderFinalSize { get; set; }
      protected int GuiBuilderTallestElementInCurrentRow { get; set; }
      protected int GuiBuilderWidthOfCurrentRow { get; set; }
  
      public GameConfigurationView(GameController controller)
      {
          InitializeComponent();
          this.Controller = controller;
          this.GuiBuilder();
          this.menuButtonStartGame.Width = this.Width;
          this.Size = this.GuiBuilderFinalSize;
      }
  
      private void GameConfigurationView_FormClosed(object sender, FormClosedEventArgs e)
      {
          this.Controller.ShowStartView();
      }
  
      /// &lt;summary&gt;
      /// Builds the gui based on the configuration of the selected GameVariant.
      /// &lt;/summary&gt;
      protected void GuiBuilder()
      {
          XmlNodeList configuration = this.Controller.SelectedGameVariant.GameConfigurationView;
          this.GuiBuilderNextLocation = new Point(0, 0);
          this.GuiBuilderFinalSize = new Size(0, 0);
          this.GuiBuilderTallestElementInCurrentRow = 0;
  
          for (int i = 0; i &lt; configuration.Count; i++)
          {
              this.BuildOneRowFromGameVariantConfiguration(configuration[i].SelectNodes("elements/element"));
          }
      }
  
      protected void BuildOneRowFromGameVariantConfiguration(XmlNodeList widgets)
      {
          this.GuiBuilderNextLocation = new Point(
              this.GuiBuilderNextLocation.X - 1,
              this.GuiBuilderNextLocation.Y - 1
          );
          for (int i = 0; i &lt; widgets.Count; i++)
          {
              this.GuiBuilderNextLocation = new Point(
                  this.GuiBuilderNextLocation.X - 1,
                  this.GuiBuilderNextLocation.Y
              );
              string elementType = widgets[i].SelectSingleNode("type").InnerText;
              string elementWidth = widgets[i].SelectSingleNode("width").InnerText;
              switch (elementType)
              {
                  case "SingleplayerWidget":
                      this.AddSingleplayerWidgetToGui();
                      break;
                  case "MapSelectionWidget":
                      this.AddMapSelectionWidgetToGui();
                      break;
                  case "MultiplayerWidget":
  
                      break;
                  case "NetworkClientWidget":
  
                      break;
                  case "NetworkHostWidget":
  
                      break;
                  case "startbutton":
  
                      break;
              }
          }
  
          // After the row reset &amp; update
          this.GuiBuilderNextLocation = new Point(
              0,
              this.GuiBuilderTallestElementInCurrentRow + this.GuiBuilderNextLocation.Y
          );
          if (this.GuiBuilderWidthOfCurrentRow &gt; this.GuiBuilderFinalSize.Width)
          {
              this.GuiBuilderFinalSize = new Size(
                  this.GuiBuilderWidthOfCurrentRow,
                  this.GuiBuilderFinalSize.Height + this.GuiBuilderTallestElementInCurrentRow
              );
          }
          else
          {
              this.GuiBuilderFinalSize = new Size(
                  this.GuiBuilderFinalSize.Width,
                  this.GuiBuilderFinalSize.Height + this.GuiBuilderTallestElementInCurrentRow
              );
          }
          this.GuiBuilderTallestElementInCurrentRow = 0;
          this.GuiBuilderWidthOfCurrentRow = 0;
      }
  
      protected void AddSingleplayerWidgetToGui()
      {
          // Add to gui
          this.SingleplayerWidget = new SingleplayerWidget(this.Controller);
          this.SingleplayerWidget.BackColor = SystemColors.ButtonHighlight;
          this.SingleplayerWidget.Location = this.GuiBuilderNextLocation;
          this.SingleplayerWidget.Name = "SingleplayerWidget";
          this.SingleplayerWidget.Size = new Size(225, 325);
          this.SingleplayerWidget.TabIndex = 1;
          this.SingleplayerWidget.Show();
          this.Controls.Add(this.SingleplayerWidget);
  
          // Update next location
          this.GuiBuilderNextLocation = new Point(
              this.SingleplayerWidget.Width + this.GuiBuilderNextLocation.X,
              this.GuiBuilderNextLocation.Y
          );
  
          if (this.SingleplayerWidget.Height &gt; this.GuiBuilderTallestElementInCurrentRow)
          {
              this.GuiBuilderTallestElementInCurrentRow = this.SingleplayerWidget.Height;
          }
          this.GuiBuilderWidthOfCurrentRow += this.SingleplayerWidget.Width + 1;
      }
  
      protected void AddMapSelectionWidgetToGui()
      {
          // Add to gui
          this.MapSelectionWidget = new MapSelectionWidget(this.Controller);
          this.MapSelectionWidget.BackColor = SystemColors.ButtonHighlight;
          this.MapSelectionWidget.Location = this.GuiBuilderNextLocation;
          this.MapSelectionWidget.Name = "MapSelectionWidget";
          this.MapSelectionWidget.Size = new Size(510, 325);
          this.MapSelectionWidget.TabIndex = 0;
          this.MapSelectionWidget.Show();
          this.Controls.Add(this.MapSelectionWidget);
  
          // Update next location
          this.GuiBuilderNextLocation = new Point(
              this.MapSelectionWidget.Width + this.GuiBuilderNextLocation.X,
              this.GuiBuilderNextLocation.Y
          );
  
          if (this.MapSelectionWidget.Height &gt; this.GuiBuilderTallestElementInCurrentRow)
          {
              this.GuiBuilderTallestElementInCurrentRow = this.MapSelectionWidget.Height;
          }
          this.GuiBuilderWidthOfCurrentRow += this.MapSelectionWidget.Width + 1;
      }
  }
  }
  </code></pre>
  
  <p>I appreciate your help :)</p>