Control alignment

3 posts, 1 answers
  1. Hu
    Hu avatar
    9 posts
    Member since:
    May 2020

    Posted 24 May 2020 Link to this post

    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. Answer
    Nadya
    Admin
    Nadya avatar
    464 posts

    Posted 27 May 2020 Link to this post

    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.
  3. Hu
    Hu avatar
    9 posts
    Member since:
    May 2020

    Posted 27 May 2020 in reply to Nadya Link to this post

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

Back to Top