Click here to Skip to main content
15,891,375 members
Articles / Programming Languages / C#

Save and restore Form position and layout with this component

Rate me:
Please Sign up or sign in to vote.
4.71/5 (52 votes)
25 Feb 20042 min read 136.1K   3.6K   81  
A component that allows to save and restore layout of any Form without coding.
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

namespace RealPositionTest
{
	/// <summary>
	/// Summary description for Form2.
	/// </summary>
	public class Form2 : System.Windows.Forms.Form
	{
		private RealPositionTest.UserControl1 userControl11;
		private RealPositionTest.UserControl2 userControl21;
		private RealPositionTest.UserControl1 userControl12;
		private RestoreState.RealPosition realPosition1;
		private System.ComponentModel.IContainer components;

		public Form2()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.components = new System.ComponentModel.Container();
			this.userControl21 = new RealPositionTest.UserControl2();
			this.userControl12 = new RealPositionTest.UserControl1();
			this.realPosition1 = new RestoreState.RealPosition(this.components);
			this.SuspendLayout();
			// 
			// userControl21
			// 
			this.userControl21.Location = new System.Drawing.Point(24, 16);
			this.userControl21.Name = "userControl21";
			this.userControl21.Size = new System.Drawing.Size(432, 200);
			this.userControl21.TabIndex = 1;
			// 
			// userControl12
			// 
			this.userControl12.Location = new System.Drawing.Point(40, 264);
			this.userControl12.Name = "userControl12";
			this.userControl12.Size = new System.Drawing.Size(360, 96);
			this.userControl12.TabIndex = 2;
			// 
			// realPosition1
			// 
			this.realPosition1.Parent = this;
			// 
			// Form2
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(496, 477);
			this.Controls.Add(this.userControl12);
			this.Controls.Add(this.userControl21);
			this.Name = "Form2";
			this.realPosition1.SetRestoreLocation(this, true);
			this.Text = "Form2";
			this.ResumeLayout(false);

		}
		#endregion

		private void listView1_Resize(object sender, System.EventArgs e)
		{
		}
	}
}

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
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions