I want to implement an AutoSize property in a Custom Control (not User Control), in such a way that it behaves like other standard .NET WinForms controls which implement AutoSize (ala CheckBox) in design mode.
I have the property set up, but it's the way the control behaves in design mode that bugs me. 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.
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.
Edit: I have it working using the SetBoundsCore() override, but it doesn't visually restrict a resize when AutoSize is set to true, it just has the same effect; the functionality is equivalent, but it feels unnatural.
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);
}
Any ideas on doing this the standard way?