System.Windows.Forms.ToolStripDropDownMenu.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)
		{
			// Find the widest menu item
			int widest = 0;

			foreach (ToolStripItem tsi in this.Items) {
				if (!tsi.Available)
					continue;

				tsi.SetPlacement (ToolStripItemPlacement.Main);

				widest = Math.Max (widest, tsi.GetPreferredSize (Size.Empty).Width);
			}

			int x = this.Padding.Left;
			
			if (show_check_margin || show_image_margin)
				widest += 68 - this.Padding.Horizontal;
			else
				widest += 47 - this.Padding.Horizontal;
			
			int y = this.Padding.Top;

			foreach (ToolStripItem tsi in this.Items) {
				if (!tsi.Available)
					continue;

				y += tsi.Margin.Top;

				int height = 0;
	
				Size preferred_size = tsi.GetPreferredSize (Size.Empty);

				if (preferred_size.Height > 22)
					height = preferred_size.Height;
				else if (tsi is ToolStripSeparator)
					height = 7;
				else
					height = 22;

				tsi.SetBounds (new Rectangle (x, y, widest, height));
				y += height + tsi.Margin.Bottom;
			}

			this.Size = new Size (widest + this.Padding.Horizontal, y + this.Padding.Bottom);// + 2);
			this.SetDisplayedItems ();
			this.OnLayoutCompleted (EventArgs.Empty);
			this.Invalidate ();
		}