Click here to Skip to main content
15,886,873 members
Articles / Programming Languages / C#

Form Placement Component

Rate me:
Please Sign up or sign in to vote.
3.91/5 (11 votes)
11 Nov 20036 min read 64.2K   1.4K   33  
A component class that restores a form's placement (location, size and state) to what it was when it was last closed.
<?xml version="1.0"?>
<doc>
    <assembly>
        <name>AMS.Form</name>
    </assembly>
    <members>
        <member name="T:AMS.Form.Placement">
            <summary>
              Component class that saves a form's placement (position and size) when it is 
              closed so that it can be restored the same way the next time is is created. </summary>
            <remarks>
              This class is designed to transparently save and restore a form's placement.  
              A form just needs to be associated with an instance of this class and that's it!  
              This class does all the work by handling the form's Load and Closed events, which
              in turn call the <see cref="M:AMS.Form.Placement.Restore"/> and <see cref="M:AMS.Form.Placement.Save"/> methods.
              The <see cref="P:AMS.Form.Placement.Form"/> property holds the object whose placement this class saves 
              and restores, and it may passed to the constructor.  The placement information 
              is saved and restored using an IProfile implementation (in the <see cref="P:AMS.Form.Placement.Profile"/> 
              property), which defaults to Registry.  The name of the <see cref="P:AMS.Form.Placement.Section"/> under 
              which the placement information is kept defaults to the form's Text property.  
              The <see cref="P:AMS.Form.Placement.RestoreLocation"/>, <see cref="P:AMS.Form.Placement.RestoreSize"/>, and <see cref="P:AMS.Form.Placement.RestoreState"/> 
              properties are set to true by default, so all aspects of the form's placement are saved.
              <para>
              Since this is a component, it may be added to the Designer's Toolbox to be later 
              dropped into any form that needs its placement saved and restored. </para> </remarks>
        </member>
        <member name="M:AMS.Form.Placement.#ctor">
            <summary>
              Initializes a new instance of the Placement class. </summary>
            <remarks>
              This constructor initializes all of the class's fields to null.
              It's main purpose is to allow this class to be used as a component inside
              the Form Designer -- components must have a default constructor. </remarks>
        </member>
        <member name="M:AMS.Form.Placement.#ctor(System.Windows.Forms.Form)">
            <summary>
              Initializes a new instance of the Placement class by setting the form object 
              whose placement is to be saved and restored. </summary>
            <param name="form">
              The form object whose placement is to be saved and restored. 
              It will be kept in the <see cref="P:AMS.Form.Placement.Form"/> property. </param>
            <remarks>
              This constructor allows the <see cref="P:AMS.Form.Placement.Form"/> (the one whose placement is to
              be saved and restored) to be set when the Placement object is created, rather
              than later as a separate operation.  Thus, this constructor is helpful 
              for developers who wish to use this class directly, rather than via the Form
              Designer.  </remarks>
        </member>
        <member name="M:AMS.Form.Placement.#ctor(System.Windows.Forms.Form,System.String)">
            <summary>
              Initializes a new instance of the Placement class by setting the form object whose 
              placement is to be saved and restored, as well as the section name under which
              the placement data will be stored. </summary>
            <param name="form">
              The form object whose placement is to be saved and restored. 
              It will be kept in the <see cref="P:AMS.Form.Placement.Form"/> property. </param>
            <param name="section">
              The name of the section under which the placement data will be stored inside
              the <see cref="P:AMS.Form.Placement.Profile"/>. It will be kept in the <see cref="P:AMS.Form.Placement.Section"/> property. </param>
            <remarks>
              This constructor allows the <see cref="P:AMS.Form.Placement.Form"/> (the one whose placement is to
              be saved and restored) to be set when the Placement object is created, rather
              than later as a separate operation.  In addition, it allows the name of the
              <see cref="P:AMS.Form.Placement.Section"/> to be set to something other than the form's Text property 
              (the default section name).  Thus, this constructor is helpful 
              for developers who wish to use this class directly, rather than via the Form
              Designer.  </remarks>
        </member>
        <member name="M:AMS.Form.Placement.Dispose(System.Boolean)">
            <summary>
              Releases the unmanaged resources used by this Component and optionally releases the managed resources. </summary>
            <param name="disposing">
              If true, the managed and unmanaged resources should be released; 
              otherwise only the unmanaged resources should be released. </param>
            <remarks>
              This method sets the Form property to null to disable any calls to 
              <see cref="M:AMS.Form.Placement.Restore"/> or <see cref="M:AMS.Form.Placement.Save"/>. </remarks>
        </member>
        <member name="M:AMS.Form.Placement.HandleLoad(System.Object,System.EventArgs)">
            <summary>
              Handles the form's Load event by restoring the form's location, size, and/or state from the profile.  </summary>
            <param name="sender">
              The object who sent the event. </param>
            <param name="e">
              The event data. </param>
            <remarks>
              This handler just calls the <see cref="M:AMS.Form.Placement.Restore"/> method. </remarks>
        </member>
        <member name="M:AMS.Form.Placement.HandleClosed(System.Object,System.EventArgs)">
            <summary>
              Handles the form's Closed event by saving the form's location, size, and state from the profile.  </summary>
            <param name="sender">
              The object who sent the event. </param>
            <param name="e">
              The event data. </param>
            <remarks>
              This handler just calls the <see cref="M:AMS.Form.Placement.Save"/> method. </remarks>
        </member>
        <member name="M:AMS.Form.Placement.Restore">
            <summary>
              Restores the form's location, size, and/or state from the profile.  </summary>
            <remarks>
              To restore the form's placement, the <see cref="P:AMS.Form.Placement.Form"/> must not be null and the 
              <see cref="P:AMS.Form.Placement.Section"/> must exist in the <see cref="P:AMS.Form.Placement.Profile"/>.  The aspects of 
              the placement that are restored are based on the values of the <see cref="P:AMS.Form.Placement.RestoreLocation"/>, 
              <see cref="P:AMS.Form.Placement.RestoreSize"/>, and <see cref="P:AMS.Form.Placement.RestoreState"/> properties. 
              The location will not be restored if doing so would cause the form to fall outside 
              the bounds of the available screen(s).  Also, if the form is initially minimized
              or maximized, its state will not be restored. </remarks>
            <seealso cref="M:AMS.Form.Placement.Save"/>
        </member>
        <member name="M:AMS.Form.Placement.Save">
            <summary>
              Saves the form's location, size, and state to the profile.  </summary>
            <remarks>
              To save the form's placement, the <see cref="P:AMS.Form.Placement.Form"/> must not be null. </remarks>
            <seealso cref="M:AMS.Form.Placement.Restore"/>
        </member>
        <member name="M:AMS.Form.Placement.SetFlag(AMS.Form.Placement.Flag,System.Boolean)">
            <summary>
              Turns a bit on the internal flags field on or off. </summary>
            <param name="flag">
              The bit to turn on or off. </param>
            <param name="on">
              If true, the bit is turned (ORed); otherwise it's turned off. </param>
        </member>
        <member name="P:AMS.Form.Placement.Section">
            <summary>
              Gets or sets the name of the section under which the placement data will be stored 
              in the <see cref="P:AMS.Form.Placement.Profile"/>. </summary>		
            <remarks>
              By default, this is set to the <see cref="P:AMS.Form.Placement.Form"/>'s Text property. </remarks>
            <seealso cref="P:AMS.Form.Placement.Profile"/>
        </member>
        <member name="P:AMS.Form.Placement.Form">
            <summary>
              Gets or sets the <see cref="T:System.Windows.Forms.Form"/> object associated with this object. </summary>		
            <remarks>
              This property holds the Form object whose placement is saved and restored. </remarks>
            <seealso cref="P:AMS.Form.Placement.Section"/>
        </member>
        <member name="P:AMS.Form.Placement.Profile">
            <summary>
              Gets or sets the IProfile object used for storing and retriving the placement data. </summary>		
            <remarks>
              The default IProfile object is an instance of Registry. </remarks>
            <seealso cref="P:AMS.Form.Placement.Section"/>
        </member>
        <member name="P:AMS.Form.Placement.RestoreLocation">
            <summary>
              Gets or sets whether the <see cref="P:AMS.Form.Placement.Form"/>'s location (X and Y) should be restored. </summary>		
            <remarks>
              This property is true by default.  The location will not be restored if doing so would 
              cause the form to fall outside the bounds of the available screen(s). </remarks>
            <seealso cref="P:AMS.Form.Placement.RestoreSize"/>
            <seealso cref="P:AMS.Form.Placement.RestoreState"/>
        </member>
        <member name="P:AMS.Form.Placement.RestoreSize">
            <summary>
              Gets or sets whether the <see cref="P:AMS.Form.Placement.Form"/>'s size (width and height) should be restored. </summary>		
            <remarks>
              This property is true by default. </remarks>
            <seealso cref="P:AMS.Form.Placement.RestoreLocation"/>
            <seealso cref="P:AMS.Form.Placement.RestoreState"/>
        </member>
        <member name="P:AMS.Form.Placement.RestoreState">
            <summary>
              Gets or sets whether the <see cref="P:AMS.Form.Placement.Form"/>'s state (normal, minimized, or maximized) 
              should be restored. </summary>		
            <remarks>
              This property is true by default.  If the form is initially minimized
              or maximized, its state will not be restored. </remarks>
            <seealso cref="P:AMS.Form.Placement.RestoreLocation"/>
            <seealso cref="P:AMS.Form.Placement.RestoreSize"/>
        </member>
        <member name="T:AMS.Form.Placement.Flag">
            <summary>
              Values that may be added/removed to the m_flags field
              used to determine what aspect of the form to restore. </summary>
        </member>
        <member name="T:AMS.Form.Placement.WINDOWPLACEMENT">
            <summary>
              The Win32 WINDOWPLACEMENT structure. </summary>
        </member>
        <member name="T:AMS.Form.PlacementDesigner">
            <summary>
              Designer object used to set the Form property of the Placement object. </summary>
        </member>
        <member name="M:AMS.Form.PlacementDesigner.OnSetComponentDefaults">
            <summary>
              Sets the Form property to "this" -- the form where the component is being dropped. </summary>
        </member>
        <member name="M:AMS.Form.PlacementDesigner.PostFilterProperties(System.Collections.IDictionary)">
            <summary>
              Removes properties that the form designer should not generate code for. </summary>
            <param name="properties">
              The dictionary of properties to be manipulated. </param>
        </member>
    </members>
</doc>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
United States United States
I've done extensive work with C++, MFC, COM, and ATL on the Windows side. On the Web side, I've worked with VB, ASP, JavaScript, and COM+. I've also been involved with server-side Java, which includes JSP, Servlets, and EJB, and more recently with ASP.NET/C#.

Comments and Discussions