* * *

Author Topic: [SOLVED] Change Auto position of PairSplitter ??  (Read 1797 times)

majid.ebru

  • Sr. Member
  • ****
  • Posts: 360
[SOLVED] Change Auto position of PairSplitter ??
« on: March 10, 2018, 12:43:33 pm »
Hi

i create a program like IMAGE 1.

when i change width of form i have IMAGE 2??

i want have IAMGE 3 when i change width of form?

how can i do that?

please help or giude me
« Last Edit: March 10, 2018, 07:29:33 pm by majid.ebru »

ASerge

  • Hero Member
  • *****
  • Posts: 898
Re: Change Auto position of PairSplitter ??
« Reply #1 on: March 10, 2018, 02:25:22 pm »
Sample with TSplitter.

majid.ebru

  • Sr. Member
  • ****
  • Posts: 360
Re: Change Auto position of PairSplitter ??
« Reply #2 on: March 10, 2018, 03:46:42 pm »
@ASerge thank you

TSplitter doesn't work correctly!?!

after compile your program,

please , change form to maximom then set minimun.you will see that aliment of tsplliter changed?!?!


jamie

  • Hero Member
  • *****
  • Posts: 809
Re: Change Auto position of PairSplitter ??
« Reply #3 on: March 10, 2018, 04:17:38 pm »
don't use splitters, use Tpanels to host your colors and then use the anchor editor so that the
left side of each panel will grab the adjacent component..
the for right panel you have it grab the edge of the form.

 do the same for the top and bottom.

 when you resize your form they will also resize or at by theory they will. :D

majid.ebru

  • Sr. Member
  • ****
  • Posts: 360
Re: Change Auto position of PairSplitter ??
« Reply #4 on: March 10, 2018, 04:48:36 pm »
don't use splitters, use Tpanels to host your colors and then use the anchor editor so that the
left side of each panel will grab the adjacent component..
the for right panel you have it grab the edge of the form.

 do the same for the top and bottom.

 when you resize your form they will also resize or at by theory they will. :D

but i want to change each panel?!?

how can i change width of panels?

jamie

  • Hero Member
  • *****
  • Posts: 809
Re: Change Auto position of PairSplitter ??
« Reply #5 on: March 10, 2018, 05:00:07 pm »
I don't understand, I guess what you are trying to do is proportionally adjust the widths of all panels
via when the form changes size?

 maybe you need to turn off all the auto sizing and directly set the positions and widths during the
OnSize of the form event ?


  at least that way you can directly set the sizes as you need.

howardpc

  • Hero Member
  • *****
  • Posts: 2751
Re: Change Auto position of PairSplitter ??
« Reply #6 on: March 10, 2018, 06:10:46 pm »
If you don't need splitters to change the width of individual panels, and simply want the panels always of equal width, then the following does it.
Code: Pascal  [Select]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   SysUtils, Forms, Controls, Graphics, ExtCtrls;
  9.  
  10. const
  11.   PanelCount = 4;  // set this as desired
  12.  
  13. type
  14.  
  15.   TForm1 = class(TForm)
  16.     procedure FormCreate(Sender: TObject);
  17.     procedure FormResize(Sender: TObject);
  18.   private
  19.     FPanels: array of TPanel;
  20.   end;
  21.  
  22. var
  23.   Form1: TForm1;
  24.  
  25. implementation
  26.  
  27. {$R *.lfm}
  28.  
  29. procedure TForm1.FormCreate(Sender: TObject);
  30. var
  31.   i: Integer;
  32. begin
  33.   Caption := 'Resizeable equal width panels';
  34.   Randomize;
  35.   SetLength(FPanels, PanelCount);
  36.   for i := 0 to PanelCount-1 do begin
  37.     FPanels[i] := TPanel.Create(Self);
  38.     FPanels[i].Caption := Format('Panel #%d',[i+1]);
  39.     FPanels[i].Color := RGBToColor(Random(256), Random(256), Random(256));
  40.     FPanels[i].Align := alLeft;
  41.     FPanels[i].Left := i;
  42.     FPanels[i].Parent := Self;
  43.   end;
  44. end;
  45.  
  46. procedure TForm1.FormResize(Sender: TObject);
  47. var
  48.   i, w: Integer;
  49. begin
  50.   DisableAlign;
  51.     w := ClientWidth div PanelCount;
  52.     for i := 0 to PanelCount-1 do
  53.       FPanels[i].Width := w;
  54.   EnableAlign;
  55. end;
  56.  
  57. end.

wp

  • Hero Member
  • *****
  • Posts: 4903
Re: Change Auto position of PairSplitter ??
« Reply #7 on: March 10, 2018, 06:44:40 pm »
ChildSizing is one of the less popular features, but does exactly what is required here without writing any line of code:
  • Add the 4 panels. Don't touch Align.
  • Set Constraints.MinWidth and .MinHeight of each panel to 1 (IMPORTANT!)
  • Set the form's ChildSizing.ControlsPerLine to 4 (there are 4 panels)
  • Set the form's ChildSizing.EnlargeHorizontal to crsScaleChilds
  • Set the form's ChildSizing.EnlargeVertical to crsScaleChilds
  • Set the form's ChildSizing.Layout to cclLeftToRightThenTopToBottom
  • If you want to have gaps between the panels set the form's ChildSizing.HorzontalSpacing accordingly
See what happens if you set ChildSizing.ControlsPerLine to 2...
« Last Edit: March 10, 2018, 07:35:30 pm by wp »
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

majid.ebru

  • Sr. Member
  • ****
  • Posts: 360
Re: Change Auto position of PairSplitter ??
« Reply #8 on: March 10, 2018, 07:22:04 pm »
i set these but it doesn't work?

what is my wrong?
« Last Edit: March 10, 2018, 07:27:41 pm by majid.ebru »

wp

  • Hero Member
  • *****
  • Posts: 4903
Re: Change Auto position of PairSplitter ??
« Reply #9 on: March 10, 2018, 07:27:25 pm »
How could I know? The attachment shows that childsizing is working.

[EDIT] Ah, there's a sample project now: I forgot to say that ChildSizing.layout must be set to cclLeftToRighThenLeftToBottom - I'll edit the steps above like this. The other error is that child-sized controls must not be aligned. See general instructions on http://wiki.freepascal.org/Autosize_/_Layout#Layout
« Last Edit: March 10, 2018, 07:32:49 pm by wp »
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

majid.ebru

  • Sr. Member
  • ****
  • Posts: 360
Re: Change Auto position of PairSplitter ??
« Reply #10 on: March 10, 2018, 07:29:17 pm »
If you don't need splitters to change the width of individual panels, and simply want the panels always of equal width, then the following does it.
Code: Pascal  [Select]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   SysUtils, Forms, Controls, Graphics, ExtCtrls;
  9.  
  10. const
  11.   PanelCount = 4;  // set this as desired
  12.  
  13. type
  14.  
  15.   TForm1 = class(TForm)
  16.     procedure FormCreate(Sender: TObject);
  17.     procedure FormResize(Sender: TObject);
  18.   private
  19.     FPanels: array of TPanel;
  20.   end;
  21.  
  22. var
  23.   Form1: TForm1;
  24.  
  25. implementation
  26.  
  27. {$R *.lfm}
  28.  
  29. procedure TForm1.FormCreate(Sender: TObject);
  30. var
  31.   i: Integer;
  32. begin
  33.   Caption := 'Resizeable equal width panels';
  34.   Randomize;
  35.   SetLength(FPanels, PanelCount);
  36.   for i := 0 to PanelCount-1 do begin
  37.     FPanels[i] := TPanel.Create(Self);
  38.     FPanels[i].Caption := Format('Panel #%d',[i+1]);
  39.     FPanels[i].Color := RGBToColor(Random(256), Random(256), Random(256));
  40.     FPanels[i].Align := alLeft;
  41.     FPanels[i].Left := i;
  42.     FPanels[i].Parent := Self;
  43.   end;
  44. end;
  45.  
  46. procedure TForm1.FormResize(Sender: TObject);
  47. var
  48.   i, w: Integer;
  49. begin
  50.   DisableAlign;
  51.     w := ClientWidth div PanelCount;
  52.     for i := 0 to PanelCount-1 do
  53.       FPanels[i].Width := w;
  54.   EnableAlign;
  55. end;
  56.  
  57. end.

thank you....

Code: Pascal  [Select]
  1. procedure CHG_Pos;
  2. var
  3.   i:Integer;
  4. begin
  5.   with(FormMain)do begin
  6.     i := P_P50_4.Width;  //Parent Panel
  7.     PairS_B0_2.Position := round(i div 2);
  8.     PairS_B0_3.Position := round(i div 4);
  9.     PairS_B0_4.Position := round(i div 4);
  10.   end;
  11. end;

ASerge

  • Hero Member
  • *****
  • Posts: 898
Re: Change Auto position of PairSplitter ??
« Reply #11 on: March 10, 2018, 07:30:33 pm »
There is no code at all in this project, but it works as expected.
And at the same time it contains TSplitter, for the possibility of changing the size of panels.

majid.ebru

  • Sr. Member
  • ****
  • Posts: 360
Re: Change Auto position of PairSplitter ??
« Reply #12 on: March 10, 2018, 07:36:03 pm »
How could I know? The attachment shows that childsizing is working.

[EDIT] Ah, there's a sample project now: I forgot to say that ChildSizing.layout must be set to cclLeftToRighThenLeftToBottom - I'll edit the steps above like this. The other error is that child-sized controls must not be aligned. See general instructions on http://wiki.freepascal.org/Autosize_/_Layout#Layout

but , i am thinking , that you forgotten , say (sorry):

Code: Pascal  [Select]
  1. Form1.ChildSizing.Layout := cclLeftToRightThenTopToBottom;

it worked.

@wp thank you

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus