System.Windows.Forms.ToolStripPanel.OnLayout C# (CSharp) Method

OnLayout() protected method

protected OnLayout ( System.Windows.Forms.LayoutEventArgs e ) : void
e System.Windows.Forms.LayoutEventArgs
return void
		protected override void OnLayout (LayoutEventArgs e)
		{
			// Don't see any reason to layout if we aren't created
			if (!this.Created)
				return;
				
			// The first time through, we have to layout everything where it belongs.
			// The key is that when we resize and stuff, we don't resize or move toolstrips.
			if (!done_first_layout) {
				ArrayList al = new ArrayList (this.Controls);
				al.Sort (new TabIndexComparer ());
				
				foreach (ToolStrip ts in al)
					this.AddControlToRows (ts);
					
				done_first_layout = true;
			}
			
			// Lay out all the rows
			Point position = this.DisplayRectangle.Location;

			if (this.Dock == DockStyle.Left || this.Dock == DockStyle.Right) {
				foreach (ToolStripPanelRow row in this.rows) {
					row.SetBounds (new Rectangle (position, new Size (row.Bounds.Width, this.Height)));

					position.X += row.Bounds.Width;
				}

				// Find how big we are so we can autosize ourself
				if (this.rows.Count > 0) {
					int last_row_right = this.rows[this.rows.Count - 1].Bounds.Right;

					if (last_row_right != this.Width)
						this.SetBounds (bounds.X, bounds.Y, last_row_right, bounds.Bottom);
				}
			} else {
				foreach (ToolStripPanelRow row in this.rows) {
					row.SetBounds (new Rectangle (position, new Size (this.Width, row.Bounds.Height)));

					position.Y += row.Bounds.Height;
				}

				// Find how big we are so we can autosize ourself
				if (this.rows.Count > 0) {
					int last_row_bottom = this.rows[this.rows.Count - 1].Bounds.Bottom;
				
					if (last_row_bottom != this.Height)
						this.SetBounds (bounds.X, bounds.Y, bounds.Width, last_row_bottom);
				}
			}
			
			this.Invalidate ();
			
			return;
		}