This is a migrated thread and some comments may be shown as answers.

Control alignment

2 Answers 1998 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Hu
Top achievements
Rank 1
Veteran
Hu asked on 24 May 2020, 09:54 PM

Hello,

I'm having some troubles with the alignment of any control in a layout or panel. Perhaps, I'm missing something trivial. Appreciated your help in this regard. 

The attached image shows the basic approach that I'm looking for. Using RadLayoutControl or RadPanel, I'm not able to keep any control center aligned during design time. It this possible in any way? 

Thanks

Lao

 

2 Answers, 1 is accepted

Sort by
0
Accepted
Nadya | Tech Support Engineer
Telerik team
answered on 27 May 2020, 09:28 AM

Hello Lao,

To keep the controls center-aligned in some panel (RadPanel or RadLayoutControl) it is suitable to use set the Anchor or Dock property. The main benefit here is that the controls do not have a specific location and size. This way when the form is resized the controls will fit in the available space.

Controls are anchored by default to the top left of the form which means when the form size will be changed, their distance from the top left side of the form will remain constant. If you change the control anchor to top, bottom, left, right then the control will keep the same distance from all four sides of the form when it is resized. Thus, the control will keep centered when resizing.

I would recommend you to have a look at the following MSDN articles which give more information about anchoring and docking controls on the form:

https://docs.microsoft.com/en-us/dotnet/framework/winforms/controls/how-to-anchor-controls-on-windows-forms
https://docs.microsoft.com/en-us/dotnet/framework/winforms/controls/how-to-dock-controls-on-windows-forms

This sounds more like a general programming question about controls alignment. This is why I made some research in StackOverflow and found out the following threads that have already been addressed on the same topic:

https://stackoverflow.com/questions/10786835/how-to-set-controls-on-center-of-the-winform
https://stackoverflow.com/questions/10599961/align-controls-to-center-in-a-flowlayout
https://stackoverflow.com/questions/26581535/what-is-the-difference-between-dock-and-anchor

I hope this information helps. If you need further assistance do not hesitate to contact me.

Regards,
Nadya
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
0
Hu
Top achievements
Rank 1
Veteran
answered on 27 May 2020, 10:54 AM

Hi Nadya, thanks for your reply and suggested links. Appreciated.

Tags
General Discussions
Asked by
Hu
Top achievements
Rank 1
Veteran
Answers by
Nadya | Tech Support Engineer
Telerik team
Hu
Top achievements
Rank 1
Veteran
Share this question
or