Delphi 中的流体表单布局
我们开发了一个软件。在此软件中,我们根据不同的情况在不同的输入屏幕上显示和隐藏一些控件。
当我们隐藏一个控件时,会发生的情况是该控件占用的空间保持原样,并且布局有时看起来非常糟糕,特别是。在具有大量控件的屏幕中。我们的客户不喜欢这样,并要求我们对此采取措施。
我的问题: 是否有某种方法可以创建流体布局,以便当隐藏控件时,其余控件会自动调整自己以填充隐藏控件留下的空白空间,并且当显示控件时,它们应该自动为控件让路并相应地调整自己。
我知道我们可以通过编码来实现这一点,但这需要在每个屏幕中使用大量代码来调整布局。我正在寻找可以减少每个屏幕编码的东西,因为有 80 多个屏幕。
请建议一些更容易出错并且可以消除每个输入屏幕中不必要的编码的方法。
We have developed a software. In this software we are show and hiding a few controls on various input screens depending on various situations.
When we hid a control what happens is that the space occupied by that control is left as it is and layout looks very bad at times esp. in screens that have larger numbers of controls. Our client does not like this and has asked us to do something about this.
My question:
Is there some way by which we can create Fluid Layouts so that when a control is hidden the rest of the controls automatically adjusts themselves to fill the empty space left by the control hidden and when the control is show they should automatically make way for the control and adjust themselves accordingly.
I know we can achieve this by coding but that will require a lot of code in each screen for adjusting the layout. I am looking something which will reduce coding in each screen as there are 80+ screens.
Please suggest some way which is less error pron and can get rid of unnecessary coding in each input screen.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我认为最好的选择是使用一个组件来处理运行时表单上 vcl 控件的布局(取决于您定义的条件)。我建议您尝试 Devexpress ExpressLayout Control
您可以在这里找到两个很棒的演示视频
(来源:devexpress.com)
您可以检查这些功能
自动管理< /strong> - 控件组和单个控件元素由布局控件自动管理。您永远不必担心逐像素定位。
表单自动调整大小 - 表单可以自动调整大小以最适合其内容。
再见。
I think your best option is to use a component that handles the layout of your vcl controls on your form in runtime (depending on the conditions that you define). I recommend you try the Devexpress ExpressLayout Control
you can find two great demo videos here
(source: devexpress.com)
You can check these features
Auto-Management - Control groups and individual control elements are automatically managed by the Layout Control. You never worry about pixel-by-pixel positioning.
Form auto-sizing - The form can be automatically resized to fit its contents best.
Bye.
现在,我不确定您的布局有多复杂,但我想您可以使用 TFlowPanel 和/或 TGridPanel 来实现此目的。 Flowpanel 对改变可见性的组件有很好的处理能力。我不确定 gridpanel 处理同样的事情效果如何......
Now, I'm not sure how complex layout you have, but I guess you can use TFlowPanel and/or TGridPanel for this. Flowpanel has a nice handling of components that change visiblity. I'm not sure how well gridpanel handles the same...
您动态隐藏哪种控件,自动填充空间是什么意思?
我不知道是不是这么简单:将控件放在面板上,然后使用对齐alTop/alClient/alBottom。当您隐藏某个面板时,所有其他面板将自动向上移动。
但有一个问题:如果你想再次显示一个面板,面板的顺序有时可能会被搞乱......可以通过手动设置 .Top 属性来修复,或通过设置 .Height := 1; 来“隐藏”;
What kind of controls are you dynamically hiding, and what do you mean with auto fill space?
I do not know if it is as this simple: place controls on panels, and use align alTop/alClient/alBottom. When you hide a panel, all other panels will move automatically up.
One problem though: if you want to show a panel again, the order of panels can sometimes be screwed up... Can be fixed by manually setting .Top property, or "hide" by setting .Height := 1;
我对复杂布局所做的实际上是将其分成几个选项卡。这有两个优点。它简化了表单布局,并允许您根据其他选项卡中的选择显示和隐藏整个选项卡。
What I would do with a complex layout is actually split it up into several tabs. This has two advantages. It simplifies the form layout, and allows you to show and hide whole tabs depending on choices made in other tabs.
Raize 组件 有一个 TRzFlowPanel UI 组件。正是您所追求的。
Raize Components have a TRzFlowPanel UI component. Does exactly what you're after.