Note that there are some explanatory texts on larger screens.

plurals
  1. POChange the Position of the Modal form at runtime
    text
    copied!<p>There is a modal form in my Delphi 2007 application. I already have applied MinHeight,MaxHeight, MinWidth and MaxWidth constraints on the form. </p> <p>If the screen resolution is below the Min/Max constraints, I want to re-size and re-position the form according to the screen resolution.</p> <p>I have written the following code in <em>OnCreate</em> event handler function to handle the screen resolution.</p> <pre><code>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 &gt; WorkArea.BottomRight.X) then begin if(Self.Constraints.MaxWidth &gt; 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 &gt; WorkArea.BottomRight.Y) then begin if(Self.Constraints.MaxHeight &gt; 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; </code></pre> <p>At design time I've set the <em>Position</em> property as follows</p> <pre><code>Position := poCentreScreen </code></pre> <p>Now there are three problems I am facing when the screen resolution is low like 1024x768 and Min &amp; Max Height/Width constraint values are above this resolution.</p> <p>I am changing the <em>Position</em> property to <em>poDesigned</em> because otherwise the form doesn't move to the position where I want it to be. </p> <p>When I run my application on system have dual monitors it behaves unexpectedly. </p> <p>I have also added a custom menu item in the system menu of the form and when I change the <em>Position</em> property to <em>poDesigned</em> in <em>OnCreate</em> function it resets the system menu and removes the custom menu item.</p> <p>Is there any way to re-size and re-position the form without modifying the <em>Position</em> property?</p> <p>Thanks in anticipation.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload