Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I would consider using the <a href="http://msdn.microsoft.com/en-us/library/system.windows.forms.control.dock.aspx" rel="nofollow noreferrer"><code>Control.Dock</code></a> property along with one of the <a href="http://msdn.microsoft.com/en-us/library/system.windows.forms.dockstyle.aspx" rel="nofollow noreferrer"><code>DockStyle</code></a> enumeration values. </p> <p>You might need to play with the <a href="http://msdn.microsoft.com/en-us/library/system.windows.forms.control.layout.aspx" rel="nofollow noreferrer"><code>Layout</code></a> too, so that you may layout your form's controls differently depending on the <code>DockStyle</code> selected.</p> <p>You will need, in my point of view, to consider the <a href="http://msdn.microsoft.com/en-us/library/system.windows.forms.control.location.aspx" rel="nofollow noreferrer"><code>Control.Location</code></a> property so that you get to know which <code>DockStyle</code> value to dock your form with.</p> <p><strong>EDIT #1</strong></p> <p>Your Windows Form has a <code>Dock</code> property as it inherits from <code>Control</code>.</p> <p>Let's consider the following :</p> <ol> <li><p>Each time your form comes closer to your right-side of the screen, for example, or of the MDI container, you want to dock right, right ? (Little word play here... =P) So, you have to subscribe to the <a href="http://msdn.microsoft.com/en-us/library/system.windows.forms.control.locationchanged.aspx" rel="nofollow noreferrer"><code>Control.LocationChanged</code></a> event.</p> <pre><code>private void myForm_LocationChanged(object sender, EventArgs e) { if (this.Location.X &gt; 900) then this.Dock = DockStyle.Right; else if (this.Location.X &lt; 150) then this.Dock = DockStyle.Left; else if (this.Location.Y &gt; 600) then this.Dock = DockStyle.Bottom; else if (this.Location.Y &lt; 150) then this.Dock = DockStyle.Top; else this.Dock = DockStyle.None; } </code></pre></li> </ol> <p>Indeed, instead of constant values, you should use the current desktop resolution and calculate a ratio from it where you want your docking to occur.</p> <p>***Disclaimer:****This code is provided as-is and has not been tested. This algorithm is hopefully enough to guide you through the docking process as you need it. Further assistance may be brought upon request.* =)</p> <p>It seems the <a href="http://msdn.microsoft.com/en-us/library/system.windows.forms.form.desktoplocation.aspx" rel="nofollow noreferrer"><code>Form.DesktopLocation</code></a> property is the righter tool for the job as for your main window, meaning your MDI container, for instance. As for the other windows, I would go along with something that looks like the code sample provided.</p> <p>Does this help?</p> <p><strong>EDIT #2</strong></p> <p>If you want to prevent Form's overlapping, perhaps the <a href="http://msdn.microsoft.com/fr-fr/library/system.windows.forms.control.bringtofront(VS.80).aspx" rel="nofollow noreferrer"><code>Control.BringToFront()</code></a> method could do it before or after your call to the <a href="http://msdn.microsoft.com/en-us/library/system.windows.forms.control.show.aspx" rel="nofollow noreferrer"><code>Control.Show()</code></a> method, depending on what works best for you.</p>
    singulars
    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.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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