私のDelphi2007アプリケーションにはモーダルフォームがあります。フォームにMinHeight、MaxHeight、MinWidth、MaxWidthの制約をすでに適用しています。
画面の解像度が最小/最大の制約を下回っている場合は、画面の解像度に応じてフォームのサイズと位置を変更したいと思います。
画面解像度を処理するために、 OnCreateイベントハンドラー関数で次のコードを記述しました。
procedure TfrmMyForm.FormCreate(Sender: TObject);
var
WorkArea: TRect;
iTitleHeight: Integer;
begin
inherited;
//-------------------------------------------------------------------
//Adjust Height/Width of the form if min/max values
//don't fall under the current resolution.
iTitleHeight := GetSystemMetrics(SM_CYCAPTION); //Height of titlebar
WorkArea := Screen.WorkAreaRect;
if(Self.Constraints.MinWidth > WorkArea.BottomRight.X) then
begin
if(Self.Constraints.MaxWidth > WorkArea.BottomRight.X) then
begin
Self.Constraints.MinWidth := WorkArea.BottomRight.X;
Self.Constraints.MaxWidth := WorkArea.BottomRight.X;
Self.Position := poDesigned;
SetBounds(0,0,WorkArea.BottomRight.X, WorkArea.BottomRight.Y - 5);
end
else
begin
Self.Constraints.MinWidth := WorkArea.BottomRight.X;
end;
end;
if(Self.Constraints.MinHeight > WorkArea.BottomRight.Y) then
begin
if(Self.Constraints.MaxHeight > WorkArea.BottomRight.Y) then
begin
Self.Constraints.MinHeight := WorkArea.BottomRight.Y - iTitleHeight;
Self.Constraints.MaxHeight := WorkArea.BottomRight.Y;
Self.Position := poDesigned;
SetBounds(0,0,WorkArea.BottomRight.X, WorkArea.BottomRight.Y - 5);
end
else
begin
Self.Constraints.MinHeight := WorkArea.BottomRight.Y;
end;
end;
//-------------------------------------------------------------------
end;
設計時に、Positionプロパティを次のように設定しました
Position := poCentreScreen
画面の解像度が1024x768のように低く、最小および最大の高さ/幅の制約値がこの解像度を超えている場合に直面する3つの問題があります。
PositionプロパティをpoDesignedに変更します。そうしないと、フォームが目的の位置に移動しません。
デュアルモニターを搭載したシステムでアプリケーションを実行すると、予期しない動作をします。
また、フォームのシステムメニューにカスタムメニュー項目を追加しました。OnCreate関数でPositionプロパティをpoDesignedに変更すると、システムメニューがリセットされ、カスタムメニュー項目が削除されます。
Positionプロパティを変更せずにフォームのサイズと位置を変更する方法はありますか?
期待してくれてありがとう。