How to position a sub-form lazarus / 21-General ---------------------------------------------------------------------- Neville · 2024-01-26 11:23 I have a main form which in certain circumstances will bring up a sub- form.  Does anyone know how I can control the position of the sub-form to a fine degree based on the position of the main form, and other factors? I'm particularly interested in Windows. ---------------------------------------------------------------------- dsiders · 2024-01-26 13:58 Quote from: Neville on January 26, 2024, 12:23:41 pmI have a main form which in certain circumstances will bring up a sub-form.  Does anyone know how I can control the position of the sub-form to a fine degree based on the position of the main form, and other factors? I'm particularly interested in Windows. You can use Top, Left, Width, and Height to figure out the position for your other form. There aren't any pre-built routines for this that I am aware of. If you're using Lazarus 3.0, there is the TForm.ScreenSnap and TForm.SnapOptions properties. https://dsiders.gitlab.io/lazdocsnext/lcl/forms/tcustomform.screensnap .html https://dsiders.gitlab.io/lazdocsnext/lcl/forms/tcustomform.screensnap .html ---------------------------------------------------------------------- cdbc · 2024-01-26 14:01 Hi Well, you have your mainform's left & top props at hand, so you feed your subform, on creation the left & top it should be placed at, in relation to the mainform. Something like this:Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.Button1Click(Sender: TObject);begin  with TSubForm.Create(nil) do try    Left:= Self.Left + 128; // <---    Top:= Self.Top + 96;   // <---    Showmodal;  finally Free; end;end; Regards Benny ---------------------------------------------------------------------- KodeZwerg · 2024-01-26 14:05 Quickly written an example that ensure that however you leave or resize the second form, when you let it show again it be centered over mainform: (uses Types) Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.Button1Click(Sender: TObject);var  MainFormPos: TPoint;  MainFormSize: TSize;  SecondFormSize: TSize;  SecondFormPos: TPoint;begin  // store main form location  MainFormPos := Point(Form1.Left, Form1.Top);  // store mainform size  MainFormSize := Size(Form1.Width, Form1.Height);  // store second form size  SecondFormSize := Size(Form2.Width, Form2.Height);  // calculate new postion, centered over main  SecondFormPos := Point(MainFormPos.X + (MainFormSize.cx - SecondFormSize.cx) div 2,                         MainFormPos.Y + (MainFormSize.cy - SecondFormSize.cy) div 2);  // update the second form  Form2.SetBounds(SecondFormPos.X, SecondFormPos.Y, Form2.Width, Form2.Height);  // show the second form  Form2.Show;end;