Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you have multiple monitors, I believe the screen UI dimensions are simply larger. So the normal "1 monitor" approach of storing and restoring the location will just work. I haven't tried this because I am away from my second monitor but it shouldn't be hard to test. The way you asked the Question is seems like you haven't tested it. </p> <p>Your second requirement will mean you will have to check the max sceen dimensions when restoring the app, and then reposition as necessary. To do this latter bit, I use this code:</p> <pre><code> private System.Drawing.Rectangle ConstrainToScreen(System.Drawing.Rectangle bounds) { Screen screen = Screen.FromRectangle(bounds); System.Drawing.Rectangle workingArea = screen.WorkingArea; int width = Math.Min(bounds.Width, workingArea.Width); int height = Math.Min(bounds.Height, workingArea.Height); // mmm....minimax int left = Math.Min(workingArea.Right - width, Math.Max(bounds.Left, workingArea.Left)); int top = Math.Min(workingArea.Bottom - height, Math.Max(bounds.Top, workingArea.Top)); return new System.Drawing.Rectangle(left, top, width, height); } </code></pre> <p>I call this method when restoring the form. I store the screen geometry in the registry on form close, and then read the geometry on form open. I get the bounds, but then constrain the restored bounds to the actual current screen, using the method above. </p> <p>Save on close: </p> <pre><code> // store the size of the form int w = 0, h = 0, left = 0, top = 0; if (this.Bounds.Width &lt; this.MinimumSize.Width || this.Bounds.Height &lt; this.MinimumSize.Height) { // The form is currently minimized. // RestoreBounds is the size of the window prior to last minimize action. w = this.RestoreBounds.Width; h = this.RestoreBounds.Height; left = this.RestoreBounds.Location.X; top = this.RestoreBounds.Location.Y; } else { w = this.Bounds.Width; h = this.Bounds.Height; left = this.Location.X; top = this.Location.Y; } AppCuKey.SetValue(_rvn_Geometry, String.Format("{0},{1},{2},{3},{4}", left, top, w, h, (int)this.WindowState)); </code></pre> <p>Restore on form open: </p> <pre><code> // restore the geometry of the form string s = (string)AppCuKey.GetValue(_rvn_Geometry); if (!String.IsNullOrEmpty(s)) { int[] p = Array.ConvertAll&lt;string, int&gt;(s.Split(','), new Converter&lt;string, int&gt;((t) =&gt; { return Int32.Parse(t); })); if (p != null &amp;&amp; p.Length == 5) this.Bounds = ConstrainToScreen(new System.Drawing.Rectangle(p[0], p[1], p[2], p[3])); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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