<p>I assumed that the C# margin property had a meaning like in CSS - the spacing around the outside of the control. But Margin values seem to be ignored to matter what values I enter.</p>

<p>Then I read on the SDK: </p>

<blockquote>
  <p>Setting the Margin property on a
  docked control has no effect on the
  distance of the control from the the
  edges of its container.</p>
</blockquote>

<p>Given that I'm placing controls on forms, and perhaps docking them, what does the Margin property get me?</p>

[{'answer_id': 75850, 'author': 'Philip Rieck', 'author_id': 12643, 'author_profile': 'https://Stackoverflow.com/users/12643', 'pm_score': 4, 'selected': True, 'text': '<p>The margin property is used by whatever layout engine your control host (Panel, for example) is using, in whatever way that layout engine sees fit.   However, it is best used for spacing just as you assume.   Just read the documentation for that specific layout engine.</p>\n\n<p>It can be very handy when using a FlowLayoutPanel or TableLayoutPanel, for example - to either reduce the default padding or space things out a bit.   Obviously, if you write a  custom layout provider, you can use Margin however you see fit.</p>\n'}, {'answer_id': 75911, 'author': 'OwenP', 'author_id': 2547, 'author_profile': 'https://Stackoverflow.com/users/2547', 'pm_score': 3, 'selected': False, 'text': '<p>Like Philip Rieck said, the margin property is only respected by container controls that perform layout.  Here\'s an example that makes it fairly clear how the <code>TableLayoutPanel</code> respects the Margin property:</p>\n\n<pre><code>using System.Drawing;\nusing System.Windows.Forms;\n\nnamespace WindowsFormsApplication1\n{\n    public partial class Form1 : Form\n    {\n        public Form1()\n        {\n            InitializeComponent();\n\n            TableLayoutPanel pnl = new TableLayoutPanel();\n            pnl.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50));\n            pnl.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50));\n            pnl.Dock = DockStyle.Fill;\n            this.Controls.Add(pnl);\n\n            Button btn1 = new Button();\n            btn1.Text = "No margin";\n            btn1.Dock = DockStyle.Fill;\n\n            Button btn2 = new Button();\n            btn2.Margin = new Padding(25);\n            btn2.Text = "Margin";\n            btn2.Dock = DockStyle.Fill;\n\n            pnl.Controls.Add(btn1, 0, 0);\n            pnl.Controls.Add(btn2, 1, 0);\n        }\n    }\n}</code></pre>\n\n<p>I believe the only .NET 2.0 built-in controls that respect this property are <code>FlowLayoutPanel</code> and <code>TableLayoutPanel</code>; hopefully third-party components respect it as well.  It has basically no effect in other scenarios.</p>\n'}, {'answer_id': 47569131, 'author': 'Pavel K', 'author_id': 1948038, 'author_profile': 'https://Stackoverflow.com/users/1948038', 'pm_score': 0, 'selected': False, 'text': '<p>Control.Margin property could be also useful at design time if you do not use layout container, but rather place controls manually.</p>\n\n<p>It affects the distance between manually dragged controls at which <a href="https://stackoverflow.com/questions/1376622/change-spacing-of-snaplines-in-visual-studio#answer-15649647">snaplines appear</a>.</p>\n\n<p>E.g. for default margin value of 3 for text box you would have this snaplines:</p>\n\n<p><a href="https://i.stack.imgur.com/HR89v.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/HR89v.png" alt="enter image description here"></a></p>\n\n<p>And for margin of 10 - these (label has margin of 3 in both cases):</p>\n\n<p><a href="https://i.stack.imgur.com/rlKfs.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/rlKfs.png" alt="enter image description here"></a></p>\n\n<p>So if you have some strict guidelines for you UI then you just set the margins as you need and drag controls to the snaplines.</p>\n'}]
['https://Stackoverflow.com/questions/75777', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/12597/']