'Firemonkey Form always restores to wsNormal

I don't know if this could be a BUG or just some configuration.

By setting the form to WndowState = wsMaximized and pressing Windows+D (Show Desktop), when the form is restored from the taskbar the WindowState changes to WndowState = wsNormal.

This only happens in Firemonkey, in VCL it doesn't.

Would there be any solution to keep the form always in wsMaximized?



Solution 1:[1]

I think this ought to be reported as a bug.

But I think I have a workaround to this. When the form is hidden the OnDeactivate event is fired. Of course that is also fired if another form takes the focus. But if SetBounds() is then called without OnActivate being fired first, as far as I've been able to tell, this only happens when the form is being shown again from the Show Desktop state.

So this code seems, from the testing I've done, to resolve the issue:

type
  TForm1 = class(TForm)
    procedure FormActivate(Sender: TObject);
    procedure FormDeactivate(Sender: TObject);
  private
    WasMaximised:   Boolean;
  public
    procedure   SetBounds(ALeft, ATop, AWidth, AHeight: Integer); override;
  end;

var
  Form1: TForm1;

implementation

{$R *.fmx}

procedure TForm1.FormActivate(Sender: TObject);
begin
  WasMaximised:=False;
end;

procedure TForm1.FormDeactivate(Sender: TObject);
begin
  WasMaximised:=WindowState=TWindowState.wsMaximized;
end;

procedure TForm1.SetBounds(ALeft, ATop, AWidth, AHeight: Integer);
begin
  inherited;
  if WasMaximised then begin
    WasMaximised:=False;
    WindowState:=TWindowState.wsNormal;
    WindowState:=TWindowState.wsMaximized;
  end;
end;

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1