Recent

Author Topic: Forms won't maximize on startup  (Read 6580 times)

William Marshall

  • Jr. Member
  • **
  • Posts: 52
Forms won't maximize on startup
« on: August 02, 2017, 06:11:22 pm »
     When I run my program all the forms appear at the positions they have in the designer, even though all their WindowState properties are wsMaximized.  And even though they should all be maximized, their Maximize border icons are the plain square maximize icon.  Clicking on that icon moves the form to its proper maximized position, and then clicking on the double-square Restore icon moves it back to its designer position, as expected if WindowState had been wsNormal originally.  There is nothing in any of the form's event handlers that affect its size, position, or state.  But if I set Left:=0, Top:=0, Height:=Screen.Height, Width:=Screen.Width, and WindowState:=wsMaximized explicitly in FormCreate, the form is almost at the right position, but still with the Maximize icon.  Clicking on that icon slightly decreases the height of the form's caption strip, resulting in a normal-looking maximized form.  I've tried simulating a mouse click on the maximize icon in FormActivate, but it has no effect.
     I may very well have done something silly when I was exploring the various settings, but I can't figure out what.  Why is wsMaximized being treated as wsNormal?  How can I make these forms behave?
Lazarus 1.8.0; fpc 3.0.4; Windows 10

Bart

  • Hero Member
  • *****
  • Posts: 5290
    • Bart en Mariska's Webstek
Re: Forms won't maximize on startup
« Reply #1 on: August 02, 2017, 07:37:48 pm »
As always:
- which Lazarus version
- which fpc version
- which OS
- which WidgetSet (win32, win64, GTK2, GTK3, QT, QT5, carbon, cocoa)?

Do you have the same problem with a project consiting of only 1 empty form with WindoState set to wsmaximized?

Bart

William Marshall

  • Jr. Member
  • **
  • Posts: 52
Re: Forms won't maximize on startup
« Reply #2 on: August 02, 2017, 08:45:01 pm »
Sorry. Chronic absent-mindedness.  Lazarus 1.6.4; fpc 3.0.2; Windows 10; Win32/Win64

With a new project consisting of just a small empty form: Starting with wsNormal, maximizing and restoring work as expected; starting with wsMaximized, the form does indeed start maximized (unlike in my program), but restore moves the top left corner to the designed position, keeping the same maximized size.  Maximize then moves the form back to the upper left corner of the screen.  I don't think I've ever tried that in a new project.  Is that typical behavior?  I expected the restored size to be what it is in the Designer.
Lazarus 1.8.0; fpc 3.0.4; Windows 10

Bart

  • Hero Member
  • *****
  • Posts: 5290
    • Bart en Mariska's Webstek
Re: Forms won't maximize on startup
« Reply #3 on: August 02, 2017, 10:57:57 pm »
I don't think I've ever tried that in a new project.  Is that typical behavior?  I expected the restored size to be what it is in the Designer.

I would expect that too.
On Linux will start maximized.
Un-maximizing the form will however NOT restore it to designer values.
(Using Lazarus trunk)

Please test with either trunk or 1.8RC3.
If the issue persist, then please report in the bugtracker ASAP (1.8 is about to be released very soon).

Bart
« Last Edit: August 02, 2017, 10:59:48 pm by Bart »

ASerge

  • Hero Member
  • *****
  • Posts: 2242
Re: Forms won't maximize on startup
« Reply #4 on: August 03, 2017, 02:14:38 am »
Lazarus 1.8RC3; Windows 7. The same behavior as described by @William Marshall.

RAW

  • Hero Member
  • *****
  • Posts: 868
Re: Forms won't maximize on startup
« Reply #5 on: August 03, 2017, 04:25:18 am »
Quote
Un-maximizing the form will however NOT restore it to designer values.
If you use SetBounds in OnCreate and set the form to wsMaximized (ObjectInspector) then it will restore into the OnCreate values...
But if you use WindowState:= wsMaximized; inside OnCreate it will not work...  funny ...  :)
Windows 7 Pro (x64 Sp1) & Windows XP Pro (x86 Sp3).

Bart

  • Hero Member
  • *****
  • Posts: 5290
    • Bart en Mariska's Webstek
Re: Forms won't maximize on startup
« Reply #6 on: August 03, 2017, 02:13:37 pm »
Un-maximizing the form will however NOT restore it to designer values.

Already reported long time ago as issue 22771.

Bart

William Marshall

  • Jr. Member
  • **
  • Posts: 52
Re: Forms won't maximize on startup
« Reply #7 on: August 03, 2017, 09:42:17 pm »
Putting  SetBounds(0,0,Screen.Width,Screen.Height);  in FormCreate of my main form helped, though the height was too great, as I suspected it would be.  In looking in the forum for information about screen sizes, I found that someone had suggested using the following to find the size of the screen available without the taskbar.
Code: Pascal  [Select][+][-]
  1. Left:=Screen.WorkAreaLeft-4;
  2. Top:=Screen.WorkAreaTop;
  3. Width:=Screen.Width;
  4. Height:=Screen.WorkAreaHeight-GetSystemMetrics(SM_CYCAPTION);
Substituting those lines for SetBounds in FormCreate worked somehow.  The form was not only the right size, it was actually maximized - the Restore icon was showing.  Not only that, all the forms, except for one, that are supposed to be maximized actually are!  I don't know why that form won't behave.  Its properties are identical to those of the other forms.
One more thing.  I commented out those four lines in FormCreate, and the form is still maximized on startup.  I don't understand at all, but with the exception of that one form, everything seems to work properly now.  Can anyone offer an explanation for all this?
Lazarus 1.8.0; fpc 3.0.4; Windows 10

RAW

  • Hero Member
  • *****
  • Posts: 868
Re: Forms won't maximize on startup
« Reply #8 on: August 04, 2017, 12:16:04 am »
Are you sure you didn't setup something in the object inspector ?

What's wrong with
Code: Pascal  [Select][+][-]
  1. SetBounds(0, 0, Screen.WorkAreaWidth, Screen.WorkAreaHeight);
And without seeing the rest of your code it's hard to say something ...

EDIT: OK maybe better this:
Code: Pascal  [Select][+][-]
  1. SetBounds(Screen.WorkAreaLeft, Screen.WorkAreaTop, Screen.WorkAreaWidth, Screen.WorkAreaHeight);
« Last Edit: August 04, 2017, 01:23:08 am by RAW »
Windows 7 Pro (x64 Sp1) & Windows XP Pro (x86 Sp3).

William Marshall

  • Jr. Member
  • **
  • Posts: 52
Re: Forms won't maximize on startup
« Reply #9 on: August 04, 2017, 07:04:51 pm »
Update:  Another day, same old problem.  Today the forms are back to their old behavior.  Starting each FormCreate with 
Code: Pascal  [Select][+][-]
  1. SetBounds(Screen.WorkAreaLeft,Screen.WorkAreaTop,Screen.Width,Screen.WorkAreaHeight-GetSystemMetrics(SM_CYCAPTION));
sets them at almost the right position and size, but they're not maximized.  I swear I wrote nothing to affect size or position since my last post.  I give up.  From your comments, it seems to be a bug in the LCL.  I wish I were smart enough to help fix it.  I'll live with the SetBounds "solution" for now.  Thank you for all your suggestions.
Lazarus 1.8.0; fpc 3.0.4; Windows 10

balazsszekely

  • Guest
Re: Forms won't maximize on startup
« Reply #10 on: August 04, 2017, 08:03:29 pm »
@William Marshall

Don't set any bounds or WindowState, leave the form as you designed, then on form show:
Code: Pascal  [Select][+][-]
  1. uses LCLIntf, LCLType;
  2.  
  3. procedure TForm1.FormShow(Sender: TObject);
  4. begin
  5.   LCLIntf.ShowWindow(Form1.Handle, SW_MAXIMIZE);
  6. end;  
  7.  

William Marshall

  • Jr. Member
  • **
  • Posts: 52
Re: Forms won't maximize on startup
« Reply #11 on: August 05, 2017, 01:21:28 am »
@GetMem:

Thank you so much! It seems to work now.  I still had to leave the SetBounds line in my main form (in FormCreate), but could remove it from all the others.  Again, Thank you!
Lazarus 1.8.0; fpc 3.0.4; Windows 10

 

TinyPortal © 2005-2018