Recent

Author Topic: Component positioning to the form/Tpanel center  (Read 8693 times)

christensen

  • Full Member
  • ***
  • Posts: 127
Component positioning to the form/Tpanel center
« on: August 28, 2011, 07:36:21 pm »
How to position a component(ex. Timage) to the form/Tpanel center and keep at the center after resizing the form?

Lazarus 1.4.4, FPC 2.6.4, Windows 7 64bit, AMD Athlon 7750 black edition, Asus M3N78-CM
Lenovo L540 i7-4702MQ, Windows 10 x64,Lazarus 1.6.2,FPC 3.0

Blaazen

  • Hero Member
  • *****
  • Posts: 3241
  • POKE 54296,15
    • Eye-Candy Controls
Re: Component positioning to the form/Tpanel center
« Reply #1 on: August 28, 2011, 08:23:03 pm »
TImage has property "Center". When I set it to "True" Image keeps centered when I resize form.
In design time, you can create initial centered position by right-click on TImage, select Align ..." and set radiobuttons "Center in Window" for both Vertical and Horizontal.
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

christensen

  • Full Member
  • ***
  • Posts: 127
Re: Component positioning to the form/Tpanel center
« Reply #2 on: August 28, 2011, 09:03:30 pm »
the center property work, only i haven't set false the Anchors properties.

thanks
 
Lazarus 1.4.4, FPC 2.6.4, Windows 7 64bit, AMD Athlon 7750 black edition, Asus M3N78-CM
Lenovo L540 i7-4702MQ, Windows 10 x64,Lazarus 1.6.2,FPC 3.0

christensen

  • Full Member
  • ***
  • Posts: 127
Re: Component positioning to the form/Tpanel center
« Reply #3 on: August 30, 2011, 07:38:27 am »
OK, now i have another problem.
I have 2 forms: Mainform and Childform.(sort of MDI)
The Childform open in the Tpanel of the main form.
On the Childform I have a few components: Tedit,DateEdit,Tcombobox,Tlabel,Tmemo.
How can i setup them to keep there position as best when i resize the Mainform?
I've try to keep at the form center but it looks ugly, especial when the Mainform is resized. The same i've try to align to left,right but still ugly.
Lazarus 1.4.4, FPC 2.6.4, Windows 7 64bit, AMD Athlon 7750 black edition, Asus M3N78-CM
Lenovo L540 i7-4702MQ, Windows 10 x64,Lazarus 1.6.2,FPC 3.0

avra

  • Hero Member
  • *****
  • Posts: 2586
    • Additional info
Re: Component positioning to the form/Tpanel center
« Reply #4 on: August 30, 2011, 08:45:52 am »
Code: [Select]
function CenterInParent(Place,NumberOfPlaces,ObjectWidth,ParentWidth,CropPercent: Integer): Integer;
  {returns formated centered position of an object relative to parent.
  Place          - P order number of an object beeing centered
  NumberOfPlaces - NOP total number of places available for object beeing centered
  ObjectWidth    - OW width of an object beeing centered
  ParentWidth    - PW width of an parent
  CropPercent    - CP percentage of safe margin on both sides which we want to omit from calculation
  +-----------------------------------------------------+
  |                                                     |
  |        +--------+       +---+      +--------+       |
  |        |        |       |   |      |        |       |
  |        +--------+       +---+      +--------+       |
  |     |              |             |            |     |
  +-----------------------------------------------------+
  |     |<---------------------A----------------->|     |
  |<-C->|<------B----->|<-----B----->|<-----B---->|<-C->|
  |                    |<-D>|
  |<----------E------------>|

  A = PW-C   B = A/NOP  C=(CP*PW)/100  D = (B-OW)/2
  E = C+(P-1)*B+D }

var
  A, B, C, D: Integer;
begin
  C := Trunc((CropPercent*ParentWidth)/100);
  A := ParentWidth - C;
  B := Trunc(A/NumberOfPlaces);
  D := Trunc((B-ObjectWidth)/2);
  Result := C+(Place-1)*B+D;
end;
ct2laz - Conversion between Lazarus and CodeTyphon
bithelpers - Bit manipulation for standard types
pasettimino - Siemens S7 PLC lib

 

TinyPortal © 2005-2018