在设计时限制用户控件的大小
我有一个命名空间 Company.UI.Forms
,其中有一个继承自 System.Windows.Forms.Form
的表单基类 BaseForm
。
我需要限制此表单的大小,以便如果具体表单(例如 ExampleForm
)派生自 BaseForm
,它在 VS 设计器视图中应该具有固定大小。 固定大小应该以某种方式设置或定义(在BaseForm
ctor中?),以便派生的ExampleForm
和设计者选择它。
那可能吗?
[编辑] 目的是使用基类作为已知屏幕尺寸的 Windows CE 设备的全屏表单的模板,为此我希望能够在设计器中布置子控件。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
在标准 WinForms 中,您可以重写 SetBoundsCore 方法。 此代码将阻止基类在设计时更改它...但请记住它可以被任何继承的类覆盖:无论如何,
我已经放置了 if 因为您指定在设计时,如果您不想要一个在运行时调整大小并删除它。
In standard WinForms you can override the SetBoundsCore method. This code will prevent the base classes to change it at design time... but remember it can be overriden by any inherited class anyway:
I've put the if because you specified to be at design time, if you don't want a resize at runtime as well remove it.
好的,现在对于 CF,快速解决方案,您可以通过将 Size 存储在字段中来编写更清晰的代码......
Ok, now for CF, quick solution, you may do a cleaner code by storing Size in a field...
我不认为这种情况有任何直接支持。 控制表单上最大大小的所有值都可以被子表单覆盖。 因此,没有办法从属性角度对其进行限制。
我能想到的唯一方法是重写尺寸更改方法,并将尺寸重置为最大尺寸(如果超过)。 但这可能会产生一些不好的影响,在您决定将其作为解决方案之前,您应该先使用它。
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.
假设我们在用户控件中有一个名为“button1”的按钮。
我希望在设计时更改用户控件大小时,button1 的大小可以根据用户控件的大小进行调整。
该解决方案工作属性。
在用户控件的调整大小事件中写入此内容。
我的英语不好。我希望这个解决方案对你来说足够了。
assuming we have a button that it name be "button1" in a usercontrol.
I want،while change usercontrol size at design time،the size of button1 be adjaust with the size of usercontrol.
this solution work property.
at the Resize event of usercontrol write this.
my english language not good.i hoop this solution be sufficient for you.