System.Windows.Forms.MdiClient.LayoutMdi C# (CSharp) Method

LayoutMdi() public method

public LayoutMdi ( MdiLayout value ) : void
value MdiLayout
return void
		public void LayoutMdi (MdiLayout value) {

			// Don't forget to always call ArrangeIconicWindows 
			ArrangeIconicWindows (true);

			switch (value) {
			case MdiLayout.Cascade: {
				int i = 0;
				for (int c = Controls.Count - 1; c >= 0; c--) {
					Form form = (Form) Controls [c];

					if (form.WindowState == FormWindowState.Minimized)
						continue;

					if (form.WindowState == FormWindowState.Maximized)
						form.WindowState = FormWindowState.Normal;

					form.Width = System.Convert.ToInt32 (ClientSize.Width * 0.8);
					form.Height = Math.Max (
								System.Convert.ToInt32 (ClientSize.Height * 0.8),
								SystemInformation.MinimumWindowSize.Height + 2);

					int l = 22 * i;
					int t = 22 * i;

					if (i != 0 && (l + form.Width > ClientSize.Width || t + form.Height > ClientSize.Height)) {
						i = 0;
						l = 22 * i;
						t = 22 * i;
					}

					form.Left = l;
					form.Top = t;

					i++;
				}
				break;
				}
			case MdiLayout.TileHorizontal:
			case MdiLayout.TileVertical: {
				// First count number of windows to tile
				int total = 0;
				
				// And space used by iconic windows
				int clientHeight = ClientSize.Height;
				
				for (int i = 0; i < Controls.Count; i++) {
					Form form = Controls [i] as Form;
					
					if (form == null)
						continue;
					
					if (!form.Visible)
						continue;

					if (form.WindowState == FormWindowState.Maximized)
						form.WindowState = FormWindowState.Normal;
					else if (form.WindowState == FormWindowState.Minimized) {
						if (form.Bounds.Top < clientHeight)
							clientHeight = form.Bounds.Top;
						continue;
					}
						
					total++;
				}
				if (total <= 0)
					return;

				// Calculate desired height and width
				Size newSize;
				Size offset;

				if (value == MdiLayout.TileHorizontal) {
					newSize = new Size(ClientSize.Width, clientHeight / total);
					offset = new Size (0, newSize.Height);
				} else {
					newSize = new Size(ClientSize.Width / total, clientHeight);
					offset = new Size (newSize.Width, 0);
				}
				
				// Loop again and set the size and location.
				Point nextLocation = Point.Empty;
				
				for (int i = 0; i < Controls.Count; i++) {
					Form form = Controls [i] as Form;

					if (form == null)
						continue;

					if (!form.Visible)
						continue;

					if (form.WindowState == FormWindowState.Minimized)
						continue;

					form.Size = newSize;
					form.Location = nextLocation;
					nextLocation += offset;
				}
				
				break;
				}
			}
		}
		#endregion	// Public Instance Methods