Controlling Design-Time Resizing

I needed a very simple extension of the standard combobox so I setup my own UserControl. As comboboxes have a fixes height I wanted to prevent the user from being able to resize vertically.

I remembered from the past that this was a trivial task, but could not remember how it was done. It took me one hour of googling before I found the solution, so I decided to spare everyone else from the trouble and post it here.

To control the selection rules of your control you need to first setup a custom designer:

    public class ComboboxControlDesigner : ControlDesigner
        public override SelectionRules SelectionRules
                return SelectionRules.LeftSizeable |
                    SelectionRules.RightSizeable |
                    SelectionRules.Visible |

Use the override to return any selection options you want to support.

Then finally attach the designer to your UserControl using the Designer attribute:


To control resizing during run-time and design-time you can also just try overriding the SetBounds method of the control:

        protected override void SetBoundsCore(int x, int y, 
            int width, int height, BoundsSpecified specified)
            if (this.DesignMode)
                base.SetBoundsCore(x, y, 100, 21, specified);
                base.SetBoundsCore(x, y, width, height, specified);