Recent

Author Topic: [Solved] Align labels on the form  (Read 3779 times)

artem101

  • Full Member
  • ***
  • Posts: 103
[Solved] Align labels on the form
« on: December 28, 2024, 12:20:52 pm »
I need to place several labels in a arrow with vertical align to middle and horizontal align to right of the parent.

What I did (1st screenshot) is not exactrly what I expected.

Code: Pascal  [Select][+][-]
  1. object Form1: TForm1
  2.   Left = 272
  3.   Height = 129
  4.   Top = 250
  5.   Width = 364
  6.   Caption = 'Form1'
  7.   ChildSizing.LeftRightSpacing = 15
  8.   ChildSizing.TopBottomSpacing = 15
  9.   ChildSizing.HorizontalSpacing = 15
  10.   ChildSizing.VerticalSpacing = 15
  11.   ChildSizing.Layout = cclLeftToRightThenTopToBottom
  12.   ChildSizing.ControlsPerLine = 999
  13.   ClientHeight = 129
  14.   ClientWidth = 364
  15.   LCLVersion = '2.2.4.0'
  16.   object Label1: TLabel
  17.     Left = 15
  18.     Height = 25
  19.     Top = 15
  20.     Width = 35
  21.     Alignment = taRightJustify
  22.     Caption = 'One'
  23.     Color = clFuchsia
  24.     Font.CharSet = RUSSIAN_CHARSET
  25.     Font.Height = -19
  26.     Font.Pitch = fpVariable
  27.     Font.Quality = fqDraft
  28.     Layout = tlCenter
  29.     ParentColor = False
  30.     ParentFont = False
  31.     Transparent = False
  32.   end
  33.   object Label2: TLabel
  34.     Left = 65
  35.     Height = 25
  36.     Top = 15
  37.     Width = 35
  38.     Alignment = taRightJustify
  39.     Caption = 'Two'
  40.     Color = clRed
  41.     Font.CharSet = RUSSIAN_CHARSET
  42.     Font.Height = -19
  43.     Font.Pitch = fpVariable
  44.     Font.Quality = fqDraft
  45.     Layout = tlCenter
  46.     ParentColor = False
  47.     ParentFont = False
  48.     Transparent = False
  49.   end
  50.   object Label3: TLabel
  51.     Left = 115
  52.     Height = 25
  53.     Top = 15
  54.     Width = 48
  55.     Alignment = taRightJustify
  56.     Caption = 'Three'
  57.     Color = clLime
  58.     Font.CharSet = RUSSIAN_CHARSET
  59.     Font.Height = -19
  60.     Font.Pitch = fpVariable
  61.     Font.Quality = fqDraft
  62.     Layout = tlCenter
  63.     ParentColor = False
  64.     ParentFont = False
  65.     Transparent = False
  66.   end
  67.   object Label4: TLabel
  68.     Left = 178
  69.     Height = 25
  70.     Top = 15
  71.     Width = 38
  72.     Alignment = taRightJustify
  73.     Caption = 'Four'
  74.     Color = clAqua
  75.     Font.CharSet = RUSSIAN_CHARSET
  76.     Font.Height = -19
  77.     Font.Pitch = fpVariable
  78.     Font.Quality = fqDraft
  79.     Layout = tlCenter
  80.     ParentColor = False
  81.     ParentFont = False
  82.     Transparent = False
  83.   end
  84. end
  85.  

How to place labels as on the 2nd screenshot?
« Last Edit: December 29, 2024, 11:07:37 am by artem101 »

CM630

  • Hero Member
  • *****
  • Posts: 1310
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: Align labels on the form
« Reply #1 on: December 28, 2024, 08:27:36 pm »
I did not understand your idea exactly, but just to make sure, are you aware of the Anchor editor?
https://wiki.freepascal.org/IDE_Window:_Anchor_Editor
Лазар 4,0RC2 32 bit (sometimes 64 bit); FPC3,2,2

wp

  • Hero Member
  • *****
  • Posts: 12754
Re: Align labels on the form
« Reply #2 on: December 28, 2024, 09:05:18 pm »
Two possibilities:
  • Using the Anchor Editor (don't use ChildSizing):
    • Drop the labels on the form
    • Open the Anchor Editor
    • Select all labels
    • Anchor them vertically to the center of the form (middle button in the "Top anchoring" box)
    • Select the right-most label only. Remove its left anchor (Uncheck "Enabled" in the "Left anchoring" box). Anchor its right side to the right side of the form (Check "Enabled" in the "Right anchoring box", and press the "right-alignment" button)
    • Select the label which is supposed to be next to the right-most label. Again, remove the left anchor as before with the other label. Anchor its right side to the left side of the right-most label (Check "Enabled" in the "right anchoring" box, and click the left alignment button).
    • Repeat this step with the other labels
  • Using an auxiliary panel with Childsizing and Anchor Editor
    • Drop a panel on the form
    • Set its ChildSizing like you did with the form
    • Drop the labels on the panel --> The labels will be aligned inside the panel
    • Open the AnchorEditor and align the panel vertically to center of the form
    • Set the panel's AutoSize to true --> The panel will shrink to just enclose the labels

artem101

  • Full Member
  • ***
  • Posts: 103
Re: Align labels on the form
« Reply #3 on: December 29, 2024, 11:06:34 am »
Thanks, wp! I done this using your 1st solution.

 

TinyPortal © 2005-2018