[SOLVED] Center image lazarus / 31-LCL ---------------------------------------------------------------------- Pe3s · 2022-04-16 09:21 Hello, I have written a code that centers an Image component. What do I have to correct in the code so that the component is centered while changing the form ? 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.FormResize(Sender: TObject);var CX, CY: Integer;begin  CX := Form1.ClientWidth;  CY := Form1.ClientHeight;   Image32_1.Left := (CX-120) DIV 2;  Image32_1.Top := (CY-100) DIV 2; end; ---------------------------------------------------------------------- wp · 2022-04-16 09:39 Why "-120" and "-100"? Please be aware that at the moment there is a regression in Laz-main due to which the OnResize handler is called only when the mouse button is released. I think it is better to use anchoring to center the form: Select the image. Open the anchor editor ("View" > "Anchor Editor"). In the "Sibling" combobox of the "Left anchoring" box select the form. Click the center button in the button group below to center the image horizontally. Then repeat the same with the "Top anchoring" box. Now the image is centered within the form, and will stay there when the form size changes. ---------------------------------------------------------------------- Pe3s · 2022-04-16 09:50 dimensions 120 and 100 are the dimensions of the image and the image component ---------------------------------------------------------------------- Pe3s · 2022-04-16 09:59 @wp Super Thank you ---------------------------------------------------------------------- wp · 2022-04-16 10:04 Quote from: Pe3s on April 16, 2022, 11:50:42 amdimensions 120 and 100 are the dimensions of the image and the image component OK, then the code is correct. If you'd ever have the idea to use a differently sized image it would be better to avoid these hard-coded values and replace them by the image size values. Moreover, never use the form variable name in the code of its class (Form1.ClientWidth) - this will cause trouble once you rename the form or create a second instance of the form. 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   CX := (ClientWidth - Image1.Width) div 2;  CY := (ClientHeight - Image1.Height) div 2;