Fluid Form Layout in Delphi
Asked Answered
B

5

9

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.

Boy answered 23/11, 2009 at 5:30 Comment(0)
D
10

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

alt text
(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.

Dael answered 23/11, 2009 at 5:43 Comment(5)
Will this component allow us to have our own screen layout will is restrict us in creating our layouts?Boy
After going through ExpressLayout details it seems to be some sort of interface for allowing end users to customize the layout as per their needs. This is not what I need. The end users will not be able to modify anything. The layout should automatically adjust itself when any control is hidden or shown.Boy
@Yogi Yang 007, this component allow to the end users to customize the layout, that is correct, but this is not the only feature of this control, nor the reason for what I recommend it.Dael
+1 for (new) LayoutControl! You can also control its behaviour by code. If you hide a control, other controls will fill up the space. All our formas are always perfectly aligned by using this control.Deandra
+1 for DevExpress' LayoutControl. I don't think there's anything you want it to do that cannot be done.Islek
T
4

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...

Triple answered 23/11, 2009 at 7:59 Comment(2)
The software is for Doctors. It contains a lot of input controls some of screens are very complicated where controls are shown and hidden based on various selections at the top of the screen as well as user rights.Boy
I would go for the flow panel. Try to group related components in panels, or frames, and place this panel in a flow panel together with the other panels. When you now hide one panel, other panel will use the available space. GridPanel may be to limited for this use.Triple
P
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;

Phraseology answered 23/11, 2009 at 7:50 Comment(3)
This is what flowpanel handles better than a regular panel with topaligned childs. ;-)Triple
Yes you're true, but flowpanel is D2007+? We do not know which Delphi version he is using...Boutwell
We are using Delphi 6 and 2006. Not upgraded to any other versions and do not plan to do so in near future.Boy
L
0

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.

Leroy answered 24/11, 2009 at 11:42 Comment(0)
S
0

Raize Components have a TRzFlowPanel UI component. Does exactly what you're after.

Use TRzFlowPanel to put an empty flow panel on a form. The major difference between a traditional panel and a flow panel is the way in which controls are placed. With a traditional panel, you place a control (such as a button) in a specific location. You can freely move that control to any location within the panel using the mouse. In a flow panel, each control is placed in a specific location, regardless of where you place it with the mouse. The automatic location is controlled by the FlowStyle property. For example, using the default FlowStyle property of LeftRightTopBottom, the first control you add to the flow panel snaps to the top left corner. The second control that you add snaps next to the first control, and so on.

Supremacist answered 25/11, 2009 at 2:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.