System.Windows.Forms.ToolStripDropDown.Show C# (CSharp) Method

Show() public method

public Show ( Point position, ToolStripDropDownDirection direction ) : void
position Point
direction ToolStripDropDownDirection
return void
		public void Show (Point position, ToolStripDropDownDirection direction)
		{
			this.PerformLayout ();
			
			Point show_point = position;
			Point max_screen = new Point (SystemInformation.VirtualScreen.Width, SystemInformation.VirtualScreen.Height);
			
			if (this is ContextMenuStrip) {
				// If we are going to go offscreen, adjust our direction so we don't...
				// X direction
				switch (direction) {
					case ToolStripDropDownDirection.AboveLeft:
						if (show_point.X - this.Width < 0)
							direction = ToolStripDropDownDirection.AboveRight;
						break;
					case ToolStripDropDownDirection.BelowLeft:
						if (show_point.X - this.Width < 0)
							direction = ToolStripDropDownDirection.BelowRight;
						break;
					case ToolStripDropDownDirection.Left:
						if (show_point.X - this.Width < 0)
							direction = ToolStripDropDownDirection.Right;
						break;
					case ToolStripDropDownDirection.AboveRight:
						if (show_point.X + this.Width > max_screen.X)
							direction = ToolStripDropDownDirection.AboveLeft;
						break;
					case ToolStripDropDownDirection.BelowRight:
					case ToolStripDropDownDirection.Default:
						if (show_point.X + this.Width > max_screen.X)
							direction = ToolStripDropDownDirection.BelowLeft;
						break;
					case ToolStripDropDownDirection.Right:
						if (show_point.X + this.Width > max_screen.X)
							direction = ToolStripDropDownDirection.Left;
						break;
				}

				// Y direction
				switch (direction) {
					case ToolStripDropDownDirection.AboveLeft:
						if (show_point.Y - this.Height < 0)
							direction = ToolStripDropDownDirection.BelowLeft;
						break;
					case ToolStripDropDownDirection.AboveRight:
						if (show_point.Y - this.Height < 0)
							direction = ToolStripDropDownDirection.BelowRight;
						break;
					case ToolStripDropDownDirection.BelowLeft:
						if (show_point.Y + this.Height > max_screen.Y && show_point.Y - this.Height > 0)
							direction = ToolStripDropDownDirection.AboveLeft;
						break;
					case ToolStripDropDownDirection.BelowRight:
					case ToolStripDropDownDirection.Default:
						if (show_point.Y + this.Height > max_screen.Y && show_point.Y - this.Height > 0)
							direction = ToolStripDropDownDirection.AboveRight;
						break;
					case ToolStripDropDownDirection.Left:
						if (show_point.Y + this.Height > max_screen.Y && show_point.Y - this.Height > 0)
							direction = ToolStripDropDownDirection.AboveLeft;
						break;
					case ToolStripDropDownDirection.Right:
						if (show_point.Y + this.Height > max_screen.Y && show_point.Y - this.Height > 0)
							direction = ToolStripDropDownDirection.AboveRight;
						break;
				}
			}
		
			switch (direction) {
				case ToolStripDropDownDirection.AboveLeft:
					show_point.Y -= this.Height;
					show_point.X -= this.Width;
					break;
				case ToolStripDropDownDirection.AboveRight:
					show_point.Y -= this.Height;
					break;
				case ToolStripDropDownDirection.BelowLeft:
					show_point.X -= this.Width;
					break;
				case ToolStripDropDownDirection.Left:
					show_point.X -= this.Width;
					break;
				case ToolStripDropDownDirection.Right:
					break;
			}

			// Fix offscreen horizontal positions
			if ((show_point.X + this.Width) > max_screen.X)
				show_point.X = max_screen.X - this.Width;
			if (show_point.X < 0)
				show_point.X = 0;

			// Fix offscreen vertical positions
			if ((show_point.Y + this.Height) > max_screen.Y)
				show_point.Y = max_screen.Y - this.Height;
			if (show_point.Y < 0)
				show_point.Y = 0;

			if (this.Location != show_point)
				this.Location = show_point;

			CancelEventArgs e = new CancelEventArgs ();
			this.OnOpening (e);

			if (e.Cancel)
				return;

			// The tracker lets us know when the form is clicked or loses focus
			ToolStripManager.AppClicked += new EventHandler (ToolStripMenuTracker_AppClicked);
			ToolStripManager.AppFocusChange += new EventHandler (ToolStripMenuTracker_AppFocusChange);

			base.Show ();

			ToolStripManager.SetActiveToolStrip (this, ToolStripManager.ActivatedByKeyboard);

			this.OnOpened (EventArgs.Empty);
		}
		

Same methods

ToolStripDropDown::Show ( ) : void
ToolStripDropDown::Show ( Control control, Point position ) : void
ToolStripDropDown::Show ( Control control, Point position, ToolStripDropDownDirection direction ) : void
ToolStripDropDown::Show ( Control control, int x, int y ) : void
ToolStripDropDown::Show ( Point screenLocation ) : void
ToolStripDropDown::Show ( int x, int y ) : void

Usage Example

Example #1
0
        internal void CreateToolStrip()
        {
            if (Enabled == false)
            {
                return;
            }

            if (dropDownItems.Count == 0)
            {
                return;
            }

            var dropDownBounds = new Rectangle(Point.Empty, Owner.Size);

            for (int i = 0; i < dropDownItems.Count; i++) // Reset items.
            {
                var item = dropDownItems[i];
                item.Unselect();

                var dropDownItem = item as ToolStripDropDownItem;
                if (dropDownItem == null)
                {
                    continue;
                }

                dropDownItem.ArrowImage = ApplicationResources.Images.DropDownRightArrow;
                dropDownItem.ArrowColor = Color.Black;
            }

            var direction = ToolStripDropDownDirection.Right;

            if (Owner.IsDropDown == false)
            {
                direction = ToolStripDropDownDirection.BelowRight;
            }

            dropDownToolStrip = userDropDown == null
                ? new ToolStripDropDownMenu()
                : userDropDown;
            dropDownToolStrip.OwnerItem = this;
            dropDownToolStrip.Items.AddRange(dropDownItems);
            dropDownToolStrip.selectedItem   = dropDownToolStrip.SelectNextToolStripItem(null, true);
            dropDownToolStrip.shouldFixWidth = true;
            dropDownToolStrip.direction      = direction;
            dropDownToolStrip.Location       = DropDownDirectionToDropDownBounds(direction, dropDownBounds).Location;
            dropDownToolStrip.Disposed      += DropDownToolStrip_Disposed;
            dropDownToolStrip.Show(dropDownToolStrip.Location);

            if (uwfDropDownCreated != null)
            {
                uwfDropDownCreated(dropDownToolStrip);
            }

            pressed = true;
        }
All Usage Examples Of System.Windows.Forms.ToolStripDropDown::Show