How do you handle multiple TPanel during development?

I have several TPanel in my main form, which I show / hide depending on the parameters that the user selects. The problem is that during development I have to constantly move them in order to edit them. Is there an easier / better way that others deal with this situation?

+6
source share
7 answers

If only one panel is displayed at a time, you can use TPageControl to organize things. You can click the tabs to choose which one to work at design time, and then hide the tabs at run time or hide the tabs all the time and select pages by setting the ActivePage property .

+10
source

Use the Structure Panel to find the one you want, and then bring it to the front.

Structure Panel http://edn.embarcadero.com/article/images/33289/8.png

(But don't follow the Embarcadero example above, give your controls meaningful names to make your controls easier to tell each other.)

+4
source

If the panels are folded, you can change their order by right-clicking one at a time and choosing Control->Bring to Front or Control->Send to Back in the context menu.

+3
source

The caveat that I found while executing Panel1.Visible: = false at runtime is that it messed up the layout.
The solution I found is to make:

 //Design time //----------- Panel1.BevelOuter:= bvNone; //Make the panel look flat. //Run time when hiding the panel //------------------------------ procedure HidePanel(APanel: TPanel); var H,W: integer; begin case APanel.Align of alTop, alBottom: begin APanel.Tag:= Max(APanel.Tag, APanel.Height); APanel.Height:= 1; end; {alTop, alBottom:} alLeft, alRight: begin APanel.Tag:= Max(APanel.Tag, APanel.Width); Panel1.Width:= 1; end; {alLeft, alRight:} alNone: begin H:= Max(APanel.Tag and $FFFF, APanel.Height); W:= Max((APanel.Tag shl 16) and $FFFF0000, APanel.Width shl 16); APanel.Tag:= (H or W); APanel.Height:= 1; APanel.Width:= 1; end; {alNone} //alClient: do nothing end; end; //Run time when restoring the panel //--------------------------------- procedure UnhidePanel(APanel: TPanel); var H,W: integer; begin case APanel.Align of alTop, alBottom: begin APanel.Height:= APanel.Tag; APanel.Tag:= 0; end; {alTop, alBottom:} alLeft, alRight: begin APanel.Width:= APanel.Tag; APanel.Tag:= 0; end; {alLeft, alRight:} alNone: begin H:= APanel.Tag and $FFFF; W:= APanel.Tag shr 16; APanel.Height:= H; APanel.Width:= W; APanel.Tag:= 0; end; {alNone} //alClient: do nothing end; {case} end; 

Just hiding panels can ruin the careful alignment you created in Designtime
(especially when using splitters).
This code prevents this.
It really only works visually when the panel does not have Bevels, and the color of the panel is equal to the color of the control located on top.

+3
source

I select a frame or panel using the Object Inspector Component, and then in the main menu, click "Edit" → "Bring to Front"

(which is like opening a structure)

+2
source

I also used TPageControl, and I kept the tabs visible at design time. This gave me the convenience of using the design (by clicking on the tabs that I want). Then, at runtime, I hide the page tabs and switch the active pages to the page control using the code, as a way to switch the panel. However, this led to some terribly huge and complex forms, which, in turn, caused many problems.

In your case, I suggest you consider refactoring each panel into its own form or frame. My preference would be to use Forms rather than frameworks, and the reasons for this are well known and well documented in the Delphi world.

In my most well-structured applications, each “panel” (which implements the use of TForm, although not TFrame) is divided into different units, and this solves both your problems with development time control and leads to a more well-structured general solution.

Although I believe that the structure panel (someone else pointed out) is a big help for you when you want to work with such complex forms that the designer’s usual visual tools begin to get complicated, it’s also a good idea to consider hacking your form when you reach this point of “diminishing returns" using the Designer form, on what becomes one super-super complex form.

+1
source

For this purpose it is much easier to use frames. I usually create them at runtime and add them to the form as needed. It also makes the code more readable, as you can use the same component names (e.g. ed_Name or l_Welcome) for different frames without name conflicts, and not with ed_NameForPanel1, ed_NameForPanel3, etc.

+1
source

Source: https://habr.com/ru/post/886806/


All Articles