Click here to Skip to main content
15,891,529 members
Articles / Desktop Programming / Windows Forms

C# Form Location Manager

Rate me:
Please Sign up or sign in to vote.
2.56/5 (7 votes)
1 Nov 2005CPOL2 min read 51.1K   607   14  
An article containing details of a class that handles form locations without adding code to each form
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

namespace FormManagerExample
{
	/// <summary>
	/// Summary description for Form3.
	/// </summary>
	public class Form3 : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Label lblBtmCorner;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public Form3()
		{
			//
			// 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.lblBtmCorner = new System.Windows.Forms.Label();
			this.SuspendLayout();
			// 
			// lblBtmCorner
			// 
			this.lblBtmCorner.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
			this.lblBtmCorner.Location = new System.Drawing.Point(64, 240);
			this.lblBtmCorner.Name = "lblBtmCorner";
			this.lblBtmCorner.Size = new System.Drawing.Size(224, 23);
			this.lblBtmCorner.TabIndex = 0;
			this.lblBtmCorner.Text = "Bottom Corner Label";
			this.lblBtmCorner.TextAlign = System.Drawing.ContentAlignment.BottomRight;
			// 
			// Form3
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(292, 266);
			this.Controls.Add(this.lblBtmCorner);
			this.Name = "Form3";
			this.Text = "Form3";
			this.Resize += new System.EventHandler(this.Form3_Resize);
			this.Load += new System.EventHandler(this.Form3_Load);
			this.ResumeLayout(false);

		}
		#endregion

		private void Form3_Load(object sender, System.EventArgs e)
		{
			lblBtmCorner.Text = "Bottom Corner Label (" + this.Width + ":" + this.Height + ")"; 
		}

		private void Form3_Resize(object sender, System.EventArgs e)
		{
			lblBtmCorner.Text = "Bottom Corner Label (" + this.Width + ":" + this.Height + ")"; 
		}
	}
}

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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
Australia Australia
Luke Tupper is a software developer based in Melbourne, Victoria Australia.

Luke develops in either C# for Windows or in Objective-C for MacOSX.

Comments and Discussions