Forum > Beginners

Improving custom message box

<< < (3/3)

wp:
With this corrected, your code is placing the left/top corner of the message box over the center of the calling form. Is this intended? Or do you want to have the center of the message box over the center of the calling form? In this case you must also subtract half of the messagebox width and height from Left/Top (but it could be that the messagebox size is not yet known at this moment due to autosizing). If you set the message box's Position property to poOwnerForm and create the message box with the other form as owner you get this for free, without doing any calculation:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---  frmDialog:=TForm.CreateNew(other_form);   // other_form rather than nil!  with frmDialog do begin   ...    if other_form <> nil then      Position := poOwnerFormCenter    // remove the Top/Left calculation that was here...    else      Position := poMainFormCenter;     ShowModal;  

pascal111:

--- Quote from: wp on June 30, 2022, 07:02:27 pm ---With this corrected, your code is placing the left/top corner of the message box over the center of the calling form. Is this intended? Or do you want to have the center of the message box over the center of the calling form? In this case you must also subtract half of the messagebox width and height from Left/Top (but it could be that the messagebox size is not yet known at this moment due to autosizing). If you set the message box's Position property to poOwnerForm and create the message box with the other form as owner you get this for free, without doing any calculation:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---  frmDialog:=TForm.CreateNew(other_form);   // other_form rather than nil!  with frmDialog do begin   ...    if other_form <> nil then      Position := poOwnerFormCenter    // remove the Top/Left calculation that was here...    else      Position := poMainFormCenter;     ShowModal;

--- End quote ---

I think you are right, but regardless of the intended position I liked to place the message box in to its calling form, your code is higher of my current knowledge in Lazarus. I don't understand everything on it, and kept that to a later time when I increase my knowledge in Lazarus. Lazarus has incredibly huge libraries and tools. I didn't see a language has that volume except a language called "D", it's so huge too as I think.

I'll keep your code on my mind, and let's make discussing its details to another time.

Handoko:
That code basically means:

Create a form and set the set its_owner = caller
...
   if its_owner has been set then
      Position := center_based_on_the_owner
   else
      Position := center_based_on_main_form

Navigation

[0] Message Index

[*] Previous page

Go to full version