So I decided to give VCL styles in XE7.
Changing my style in the IDE Project, Options window from "Windows" to any
other results in the initial form in my app misbehaving. The window state
seems weird, and the minimize/maximize/close buttons don't work. And the
TMainMenu "fights" with the TToolbar for visibility.
I have to double click the title bar to resize the form before the form
starts behaving properly.
It seems that my code setting TForm.WindowState to the state when the
program was previously closed is causing some problems. Before exploring
this further, I thought I'd ask are there any known problems of this sort
with styles?
Robert Frank wrote:
> Do you have any further information or can you point me towards any
> documentation on this issue?
You are doing it in events, I see.
It's not necessarily going to work fine then, we do it like this here:
// Interface section
TBaseForm = class(TForm)
public
constructor Create(AOwner : TComponent);
end;
// Implementation section
constructor TBaseForm .Create(AOwner : TComponent);
const
ValueNotFound = Low(Integer);
var
R: TRect;
Dimension: Integer;
begin
inherited Create(AOwner);
if BorderStyle in [bsSizeable, bsSizeToolWin] then
begin
// To be able to restore on another monitor than the "default"
// we must use this value on the property.
// See TCustomForm.SetWindowToMonitor for details
DefaultMonitor := dmDesktop;
R := GetSavedRect;
if (R.Left <> ValueNotFound) then
begin
Position := poDesigned;
WindowMonitor := Screen.MonitorFromRect(R);
if R.Right - R.Left > WindowMonitor.Width then
R.Right := R.Left + WindowMonitor.Width;
if R.Bottom - R.Top > WindowMonitor.Height then
R.Bottom := R.Top + WindowMonitor.Height;
Dimension := R.Right - R.Left;
if R.Right > WindowMonitor.Left + WindowMonitor.Width then
R.Left := WindowMonitor.Left + WindowMonitor.Width - Dimension;
if R.Left < WindowMonitor.Left then
R.Left := WindowMonitor.Left;
R.Right := R.Left + Dimension;
Dimension := R.Bottom - R.Top;
if R.Bottom > WindowMonitor.Top + WindowMonitor.Height then
R.Top := WindowMonitor.Top + WindowMonitor.Height - Dimension;
if R.Top < WindowMonitor.Top then
R.Top := WindowMonitor.Top;
R.Bottom := R.Top + Dimension;
SetBounds(R.Left, R.Top, R.Right - R.Left, R.Bottom - R.Top);
end;
if MustRestoreMaximized then
WindowState := wsMaximized;
end;
end;
GetSavedRect is for you to write and must return a TRect that has
Low(Integer) in its values if nothing was ever saved.
MustRestoreMaximized is for you to implement as well and should return a
Boolean set to True if the form was maximized.
Here, this works well.
>Robert Frank wrote:
>
>> It seems that my code setting TForm.WindowState to the state when the
>> program was previously closed is causing some problems. Before exploring
>> this further, I thought I'd ask are there any known problems of this sort
>> with styles?
>
>Not just with styles, but with newer versions of Delphi / Windows as well.
>Basically, changing the window state in the creator is not really
>advisable anymore, but you'd have to show us your code to be sure.
Thanks, Olivier.
My code is simple:
Form1.WindowState := wsMaximized;
I can avoid that.
But, if a form isn't maximized, I want to have it's size and position
persistent between uses. it appears that even changing the form's .Left,
..Width, .Height, or .Width can cause problems.
Even making the changes later (in FormShow or FormActivate) seems to cause
some problems.
Do you have any further information or can you point me towards any
documentation on this issue?
Thanks!
Robert Frank wrote:
> It seems that my code setting TForm.WindowState to the state when the
> program was previously closed is causing some problems. Before exploring
> this further, I thought I'd ask are there any known problems of this sort
> with styles?
Not just with styles, but with newer versions of Delphi / Windows as well.
Basically, changing the window state in the creator is not really
advisable anymore, but you'd have to show us your code to be sure.