title: How can I implement an AutoSize property to a Custom Control?
body: <p>I want to implement an AutoSize property in a Custom Control (<em>not</em> User Control), in such a way that it behaves like other standard .NET WinForms controls which implement AutoSize (ala CheckBox) in design mode.</p>
  
  <p>I have the property set up, but it's the way the control behaves in design mode that bugs me. <s>it can still be resized, which doesn't make sense because the visual resize isn't reflected in the AutoSize and Size properties i've implemented.</s></p>
  
  <p>Standard .NET controls do not allow resizing (or even show resize handles) in design mode when AutoSize is true. I want my control to behave in the same fashion.</p>
  
  <p><strong>Edit</strong>: I have it working using the SetBoundsCore() override, but it doesn't visually <em>restrict</em> a resize when AutoSize is set to true, it just has the same effect; the functionality is equivalent, but it feels unnatural.</p>
  
  <pre><code>protected override void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified)
  {
      if (!this.auto_size)
          this.size = new Size(width, height);
      base.SetBoundsCore(x, y, this.size.Width, this.size.Height, specified);
  }
  </code></pre>
  
  <p>Any ideas on doing this the standard way?</p>