用户控件设计时支持
我们有一个类,当用户调整表单大小时,它会自动缩放表单上的所有控件。所需要的只是在表单加载时实例化表单中的类(设置并忘记)。
问题是您必须在表单加载时传递原始设计者的尺寸。这意味着它必须进行硬编码,并且如果设计人员在设计期间更改表单上的大小,则必须手动更改它。
我正在考虑将其更改为可以放置在表单上的组件。我认为这将允许我在 InitializeComponents() 中获取设计器的设置,这样您就不必稍后在表单加载时获取它。
但是,我对用户控件没有经验。
我不想在设计时设置默认的硬编码属性值,而是希望在设计时将其设置为表单的大小,并且当它在表单的 InitializeComponents() 中发生更改时,它将针对该控件进行更改。
谁能给我指点一些教程来告诉我有关设计时支持的信息,以及如何做到这一点?
我还希望(不太重要)限制此控件仅放置在表单上。
编辑:我不是在寻找缩放的解决方案。我想知道如何在设计时设置用户控件的属性,以便在设计时绑定到另一个控件的属性(随着该控件的更改而更改)。
We have a class that automatically scales all the controls on a form when the user resizes the form. All that is needed is to instantiate the class in the form once on form load (set and forget).
The problem is that you have to pass the original designer's dimensions on form load. This means it has to be hardcoded, and must be manually changed if the designer changes the size on the form during design time.
I am thinking of changing this to be a component that can be dropped on the form. I am thinking that that will allow me to grab the designer's settings as it happens in InitializeComponents(), so that you don't have to grab it later on form load.
However, I have no experience with UserControls.
I am not looking to set a default hardcoded property value at design time, but rather I want it to be set to the size of the form's at design time, and as it changes in InitializeComponents() for the form it will change for this control.
Can anyone point me to some tutorial that will tell me about design time support, and how to do this?
I am also looking (less important) to restrict this control to be dropped only on a Form.
EDIT: I am not looking for a solution for the scalling. I want to know how to set properties of a user control at design time to be bound to another control's property (change as that control changes) at design time.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据 @Blorgbeard 的评论 - 听起来您可能应该使用锚定/对接以及一些不错的布局控件(FlowPanel/TableLayoutPanel)。或者,可以在 SetBoundsCore 中完成更复杂的大小调整操作,我相信这将为您在运行时和设计时提供大小调整支持:
尽管我会说现在大多数“复杂的大小调整操作”(例如缩放子控件)作为总大小的百分比)应该可以使用 TableLayoutPanel 进行管理。
As per @Blorgbeard's comment - it sounds you should probably be using anchoring/docking along with some of the nice layout controls (FlowPanel/TableLayoutPanel). Alternatively, more complex sizing operations can be done in
SetBoundsCore
which I believe will give you sizing support at both runtime and design time:Though I would say that nowadays most "complex sizing operations" (e.g. scaling child controls as a % of total size) should be manageable with the TableLayoutPanel.