Search code examples
c#visual-studiocompact-frameworkuser-controlsdesign-time

Limit the size of a user control at design time


I have a namespace Company.UI.Forms where we have a form base class BaseForm that inherits from System.Windows.Forms.Form.

I need to limit the size of this form, so that if a concrete form, say ExampleForm, derives from BaseForm, it should have a fixed size in the VS designer view. The fixed size should be set or defined in some way (in the BaseForm ctor?) so that the derived ExampleForm and the designer picks it up.

Is that possible?

[Edit] The purpose is to use the base class as a template for a full screen form for a Windows CE device of known screen size, for which I want to be able to lay out child controls in the designer.


Solution

  • I don't believe there is any direct support for this type of scenario. All of the values which control the maximum size on a Form can be overridden by a child form. Hence there is no way to constrain it from a property perspective.

    The only way I can think of is to override the size changed method and reset the size to the max size if it ever goes over. This may have some bad effects though and you should expirement with it before you settle on it as a solution.