Topic: Form Size?

My question is: what size should I make my form(s)?
-
Jean and CDB were helping me in one of my earlier posts.  I put in the code that CDB sent me and I'm still having problems.
-
One of my users complained that my form(s) were too small.  So I'm trying to make them as large as possible.  I have 2 laptops.  If I size the form for the larger laptop then it's too big for the smaller one.
-
Since I don't know what kind of monitors my users will have, I'm looking for a way to have the program detect the screen size and adjust accordingly (if possible).
-
I added the script that CDB sent me and it's not doing what I'd hoped it would.
-
So I created a one form test program so I could play with the sizing.
-
Here's what I did: I set the size of the form to 1400 x 900. This size is bigger than my laptop screen.  I was hoping it might adjust down to fit my laptop but it doesn't do that.
I put a label and a text field on each side and top and bottom of the form.
When I run the program the right and bottom fields are not visible because the form is too big for my laptop.
-
My test program is attached.
-
Thanks, Frank

Post's attachments

Attachment icon RecordsX.zip 334.7 kb, 247 downloads since 2020-10-02 

2 (edited by sibprogsistem 2020-10-02 10:49:18)

Re: Form Size?

http://myvisualdatabase.com/forum/viewt … 186#p33186

Post's attachments

Attachment icon test.rar 2.31 kb, 204 downloads since 2020-10-02 

3 (edited by sibprogsistem 2020-10-02 10:50:02)

Re: Form Size?

http://myvisualdatabase.com/forum/misc.php?action=pun_attachment&item=7112&download=0

Post's attachments

Attachment icon Безымянный.png 186.33 kb, 105 downloads since 2020-10-02 

Re: Form Size?

sibprogsistem,
Thanks for the info.
I looked at some of your examples but some of them seem to be above my skill level.
Also, sorry, but I don't speak Russian so I'm not sure what some of the forms are doing.
-
I'm fairly new to MVD so I'm just learning about scripting.  I can understand what some of the scripting is doing but I'm not at a level where I can create complex ones myself.
-
I hadn't used 'Anchors' before so it's something new for me. 
However, I tried selecting different anchor positions and it didn't seem to have any effect on the size of my form.
-
So for me, when I create a form it opens up at the size I created.
If it's smaller than my screen size, then it displays at the original form size on the screen.
That's OK, except if it opens on a large monitor then the form is very small.
If the form is larger than my screen size, then when it opens up some of the form is outside the screen and not visible.
-
I may not be explaining myself correctly.
Is there any way to have a form open up on 'any' computer and to have it automatically adjust to the screen size?
-
Thanks, Frank

Re: Form Size?

example

procedure Form1_OnShow (Sender: TObject; Action: string);
begin

  Form1.Height:=round(Screen.Height) div 2;
  Form1.Width := round(Screen.Width) div 2;
  Form1.Top := (round(Screen.Height) - Form1.ClientHeight)  div 2;
  Form1.Left := (round(Screen.Width) - Form1.ClientWidth)  div 2;


end;
Post's attachments

Attachment icon test.rar 2.52 kb, 242 downloads since 2020-10-02 

Re: Form Size?

Thanks for your suggestions.
-
It looks to me like your procedure measures the size of the computer screen and then divides it by 2.
So when the form opens it is 1/2 the size of the screen
Then when you click on Maximize it fills the screen.
-
I noticed that if I start with a small form it works OK.
However if I work with a larger form, then when it first opens, some of the info on the form is not shown.
Then when you Maximize the form it does show up most of the fields. Depending on the original size of the form.
-
I have a pretty basic question.  When you are designing a project with forms, what size form do you begin with? e.g. 640 x 540, 800 x 650, 1250 x 650...?
-
It has been my experience so far that if I start with a form size of 1075 x 480 then it is the correct size for my smaller laptop screen.
If I start with a form of 1250 x 650 then it works OK on my larger laptop, but it is too big for my smaller laptop.  And all the changes that I have tried don't seem to help.
-
I feel like I'm missing something. Maybe you can give me some suggestions.
-
Maybe knowing which form size I should use for my forms would be a good starting point?
-
Thanks for your help, Frank

Re: Form Size?

Papafrank,


The divide by 2 centres the form it doesn't halve the form.

I don't have a different screen size to test this out on. I think we will get there with a combination of centering the form and using maximum size constraints in the object inspector.

It might help to have the following temporary debug code in the Form1_OnShow event.

showmessage('screen width = '+ intToStr(screen.width) + ' screen height = ' + intToStr(screen.height));

This will report your screen size - this is just to ensure Windows and VDB are seeing the same thing.

From here there are some other things you can try.

1. Move the screen sizing code from the On_Show event to the begin....end that by default has the 'Hello World' call in it.

2. Some code that didn't work for me when I was trying to get monitors with different magnifications to work, but it might work for you.

procedure ScaleForm  (F: TForm; ScreenWidth, ScreenHeight: LongInt) ;
begin
 F.Scaled := True;
 F.AutoScroll := False;
 F.Position := poDefaultPosOnly; //poScreenCenter;
 F.Font.Name := 'Arial';
 if (Screen.Width <> ScreenWidth) then
 begin
     F.Height :=  (F.Height * Screen.Height) div ScreenHeight;
     F.Width :=  (F.Width * Screen.Width) div ScreenWidth;
     F.ScaleBy(Screen.Width,ScreenWidth) ;
 end;
end;

Called by:

begin
  ScaleForm(frmMain,1920,1080) ; //OR   ScaleForm(frmMain,screen.width,screen.height) 
end.

The code immediately above is again  using the default begin...end that the script file will have.

3. Another option might be (based on code by Tony Bryer  SDA UK  on DelphiGroups)

procedure CentreForm(Form: TForm);
begin
    with Form do
    begin
        Left := Application.Form1.Left + (Application.Form1.Width - Width) div 2;
        if Left < 0 then Left:=0;
        Top := Application.Form1.Top + (Application.Form1.Height - Height) div 2;
        if Top <0 then Top:=0;
   end;
end;

Called by:

begin
   //ScaleForm(Form1 , Screen.Width, Screen.Height) ;
   CentreForm(Form1); //substitute the name of your main form here
end.
On a clear disk you can seek forever

8 (edited by papafrankc 2020-10-03 04:49:24)

Re: Form Size?

CDB,
Thanks for the suggestions, I'll check them out & see if they work for me
-
One question: I've been asking and haven't gotten an answer, is what form sizes do folks use when designing a project?
-
Some of my forms without too much data can fit on smaller forms.  However I have some forms with around 21 fields plus 21 labels.  So those forms obviously need to be larger.
-
To keep things uniform I make all the forms the size of the larger one.
-
It would be nice to know what size forms most folks use.  That is if there are so-called standard sizes?
-
Thanks, Frank

9 (edited by CDB 2020-10-03 09:16:58)

Re: Form Size?

Papafrank,

The answer probably depends on the screen size that each developer is using.


I have two 22" widescreen monitors which are 1920 x 1080  and a scale magnification of 125%.


My current project has a Main Form size of  1500 x 770 and a Constraint of MinHeight 452. Now this works fine on monitors with a scale of 100 or 125%  it gets the problem you are having if the monitor is 19" and has a magnification of 175%.


This is on PCs running Windows 10.

On a clear disk you can seek forever

10

Re: Form Size?

I have read that the  Delphi 'scale by' function works better if percentage scaling is used.

You could try - finding the users screen size as shown in the code snippets above and then using the scale by function increase or decrease the form size. Using your screen resolution as the default screen size.


So you would create two constants that hold your screen size - defaultScreenWidth and defaultScreenHeight and then use those to find the difference as presented by  - screen.width and screen.height (these will always be the users screen size figures).  From the result you can use the percentage figure ScaleBy(Screen.Width,percentage).

On a clear disk you can seek forever