title: Margin is not being applied
body: <p>I have a user control that I need to manually resize during runtime, although I would like the margin to be applied.  I found, from link 1 below, that for the margin to work the AutoSize property needs to be set to true.  Although, since I need to manually resize the control during runtime, the AutoSize property needs to be false to my understanding.   </p>
  
  <p>The user control (Accordion) contains a horizontal split panel where the first panel contains a button and the second panel contains a Panel control. In the image below you can see multiple "Accordions" which, in the picture, is one of the buttons. The Accordions are docked at the top of the container. The intent is when I click on the button it resizes and shows the "contents panel" and the contents panel's control. My problem is that setting the User Control's margin property does not cause them to automatically distance themselves from the other controls nor the container they are in.</p>
  
  <p><a href="https://i.stack.imgur.com/5uy01.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/5uy01.png" alt="enter image description here"></a></p>
  
  <p>Link 1:  <a href="https://stackoverflow.com/questions/14689095/winform-bottom-margin-property-doesnt-do-anything">WinForm Bottom Margin Property Doesn&#39;t Do Anything</a></p>
  
  <p>Hopefully some useful chunks of what I'm working with.</p>
  
  <pre><code>namespace CustomControls
  {
  partial class Accordion
  {
      /// &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.split = new System.Windows.Forms.SplitContainer();
          this.ToggleCollapse = new System.Windows.Forms.PictureBox();
          this.MainButton = new System.Windows.Forms.Button();
          this.contentsPanel = new System.Windows.Forms.Panel();
          ((System.ComponentModel.ISupportInitialize)(this.split)).BeginInit();
          this.split.Panel1.SuspendLayout();
          this.split.Panel2.SuspendLayout();
          this.split.SuspendLayout();
          ((System.ComponentModel.ISupportInitialize)(this.ToggleCollapse)).BeginInit();
          this.SuspendLayout();
          // 
          // split
          // 
          this.split.Dock = System.Windows.Forms.DockStyle.Fill;
          this.split.FixedPanel = System.Windows.Forms.FixedPanel.Panel1;
          this.split.IsSplitterFixed = true;
          this.split.Location = new System.Drawing.Point(0, 0);
          this.split.Margin = new System.Windows.Forms.Padding(3, 3, 3, 10);
          this.split.Name = "split";
          this.split.Orientation = System.Windows.Forms.Orientation.Horizontal;
          // 
          // split.Panel1
          // 
          this.split.Panel1.Controls.Add(this.ToggleCollapse);
          this.split.Panel1.Controls.Add(this.MainButton);
          this.split.Panel1MinSize = 0;
          // 
          // split.Panel2
          // 
          this.split.Panel2.Controls.Add(this.contentsPanel);
          this.split.Size = new System.Drawing.Size(663, 488);
          this.split.SplitterDistance = 40;
          this.split.TabIndex = 0;
          // 
          // ToggleCollapse
          // 
          this.ToggleCollapse.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
          this.ToggleCollapse.BackColor = System.Drawing.SystemColors.ActiveCaption;
          this.ToggleCollapse.Enabled = false;
          this.ToggleCollapse.Image = global::CustomControls.Properties.Resources.TrianglePointer;
          this.ToggleCollapse.Location = new System.Drawing.Point(621, 13);
          this.ToggleCollapse.Name = "ToggleCollapse";
          this.ToggleCollapse.Size = new System.Drawing.Size(39, 24);
          this.ToggleCollapse.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage;
          this.ToggleCollapse.TabIndex = 0;
          this.ToggleCollapse.TabStop = false;
          // 
          // MainButton
          // 
          this.MainButton.AutoEllipsis = true;
          this.MainButton.BackColor = System.Drawing.SystemColors.ActiveCaption;
          this.MainButton.Dock = System.Windows.Forms.DockStyle.Fill;
          this.MainButton.FlatAppearance.BorderColor = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(255)))), ((int)(((byte)(192)))));
          this.MainButton.FlatAppearance.BorderSize = 3;
          this.MainButton.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
          this.MainButton.Font = new System.Drawing.Font("Verdana", 18F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
          this.MainButton.ImageAlign = System.Drawing.ContentAlignment.MiddleRight;
          this.MainButton.Location = new System.Drawing.Point(0, 0);
          this.MainButton.Name = "MainButton";
          this.MainButton.Size = new System.Drawing.Size(663, 40);
          this.MainButton.TabIndex = 0;
          this.MainButton.Text = "Accordion Activator";
          this.MainButton.TextAlign = System.Drawing.ContentAlignment.BottomLeft;
          this.MainButton.UseVisualStyleBackColor = false;
          this.MainButton.MouseDown += new System.Windows.Forms.MouseEventHandler(this.MainButton_MouseDown);
          this.MainButton.MouseEnter += new System.EventHandler(this.MainButton_MouseEnter);
          this.MainButton.MouseLeave += new System.EventHandler(this.MainButton_MouseLeave);
          this.MainButton.MouseUp += new System.Windows.Forms.MouseEventHandler(this.MainButton_MouseUp);
          // 
          // contentsPanel
          // 
          this.contentsPanel.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
          this.contentsPanel.Dock = System.Windows.Forms.DockStyle.Fill;
          this.contentsPanel.Location = new System.Drawing.Point(0, 0);
          this.contentsPanel.Name = "contentsPanel";
          this.contentsPanel.Size = new System.Drawing.Size(663, 444);
          this.contentsPanel.TabIndex = 0;
          this.contentsPanel.MouseDown += new System.Windows.Forms.MouseEventHandler(this.Panel_MouseDown);
          this.contentsPanel.MouseLeave += new System.EventHandler(this.Panel_MouseLeave);
          this.contentsPanel.MouseMove += new System.Windows.Forms.MouseEventHandler(this.Panel_MouseMove);
          this.contentsPanel.MouseUp += new System.Windows.Forms.MouseEventHandler(this.Panel_MouseUp);
          // 
          // Accordion
          // 
          this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Inherit;
          this.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
          this.Controls.Add(this.split);
          this.DoubleBuffered = true;
          this.Margin = new System.Windows.Forms.Padding(3, 3, 3, 10);
          this.Name = "Accordion";
          this.Size = new System.Drawing.Size(663, 488);
          this.split.Panel1.ResumeLayout(false);
          this.split.Panel2.ResumeLayout(false);
          ((System.ComponentModel.ISupportInitialize)(this.split)).EndInit();
          this.split.ResumeLayout(false);
          ((System.ComponentModel.ISupportInitialize)(this.ToggleCollapse)).EndInit();
          this.ResumeLayout(false);
  
      }
  
      #endregion
  
      private System.Windows.Forms.SplitContainer split;
      private System.Windows.Forms.Button MainButton;
      private System.Windows.Forms.PictureBox ToggleCollapse;
      protected System.Windows.Forms.Panel contentsPanel;
  }
  }
  </code></pre>
  
  <p>This is when and how I manually resize</p>
  
  <pre><code>       public bool Collapsed
         {
          get
          {
              return split.Panel2Collapsed;
          }
          set
          {
              Freeze(true);
              if (Dock == DockStyle.Fill &amp;&amp; this.DesignMode)
              {
                  if (firstResize)
                  {
                      if (value)
                          this.Parent.Height = MainButtonHeight;
                      else
                          this.Parent.Height = ExpandedHeight;
                  }
                  else
                  {
                      if (value)
                          CollapseAnimation(1);
                      else
                          ExpandAnimation(5);
                  }
              }
              else
              {
                  if (firstResize)
                  {
                      if (value)
                          this.Height = MainButtonHeight;
                      else
                          this.Height = ExpandedHeight;
                      if (loadBegan)
                          firstResize = !firstResize;
                  }
                  else
                  {
                      if (value)
                          CollapseAnimation(1);
                      else
                          ExpandAnimation(5);
                  }
              }
              split.Panel2Collapsed = value;
              ToggleCollapse.Image = toggleImageNeutral;
              Freeze(false);
          }
      }
  </code></pre>