Home > database >  Align a component exactly in the middle of a panel
Align a component exactly in the middle of a panel

Time:09-27

I have a TRichEdit and a TButton on a TPanel, which is not aligned in the centre of the panel:

enter image description here

Is there a quicker way to align these components in the centre of the panel, than just by dragging it around and guessing if it is in the centre? Also, I am using Delphi 2010.

I tried selecting the components and using the alignment options: Alignment options

But it only aligned the button to the rich edit: Button aligned

CodePudding user response:

First, you must not select the panel, because that is not involved in this process.

Second, there is another toolbar Position that has a button to center the selected elements inside its parent.

I have no Delphi 2010 at hand, so I cannot provide a screenshot, but both icons look quite similar.

CodePudding user response:

Quickest way for aligning components at design time is by using right-clicking on specific component and then choosing Position->Align from the shown popup menu.

If you want to align your component to the center of the parent then chose Center in window for either horizontal or vertical alignment whichever you need. If you have multiple components selected Delphi will align the whole group to the center of the parent and not each individual component to the center of the parent.

If you want to align one component to the center position of another other component then select the two components first and then right click on the component on which you want your component to be centered on. And now in popup menu select Position->Align and in the opened window chose Centers wither for horizontal or vertical alignment based on what you need.

  • Related