Forum > Beginners

change dimension and position of a form at runtime not working!?

(1/2) > >>

Mountaineer:
Hi folks!

for most of you I'm sure this is a trivial problem, but I've been looking for a solution for hours (also here in the forum, of course), but haven't found anything suitable yet!
I try to resize a form during runtime but changing width and height only works in designer...!?
Tried to resize the form directly after creating it, but nothing happens...

The code:

--- 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";}};} ---procedure TForm1.FormCreate(Sender: TObject);begin   Form1.Left:=10;  Form1.Top:=10;  Form1.Width:=1900;  Form1.Height:=1060; end; 
Please help!

engkin:
Use OnShow instead:

--- 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";}};} ---procedure TForm1.FormShow(Sender: TObject);begin  Left:=10;  Top:=10;  Width:=1900;  Height:=1060;end;

Bart:
That should not make a difference.

Are you sure that in the ObjectInspector the Form1's OnCreate is set to TForm1.FormCreate?
You may have accidentally deselected that.
Or maybe you just wrote the TForm1.FormCreate by hand and did not set it in ObjectInspector?

Bart

lucamar:

--- Quote from: Bart on May 16, 2021, 07:57:46 pm ---That should not make a difference.
--- End quote ---

Indeed! It works as it should here.

Just one hint: instead of accessing the variable Form1 you should use the (implicit) Self, as in

--- 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";}};} ---procedure TForm1.FormCreate(Sender: TObject);begin  Left:=10;  Top:=10;  Width:=1900;  Height:=1060;end;
It makes little or no difference if there is only that one instance of the class but it's better practice.

ETA
Oh! Another thing: if the form's Position is any other than poDesigned that might be interfering with the repositioning, the resizing or both. In that case, deferring them until OnActivate should solve the problem.

engkin:
Yes, it is not needed to move to OnShow.

Navigation

[0] Message Index

[#] Next page

Go to full version