コード例 #1
0
        public virtual DropdownMenu Show(Control control)
        {
            Close();

            menu      = CreateNewMenu();
            menu.Size = new Size(control.Width + menu.Padding.Horizontal, 0);
            menu.Items.Clear();

            foreach (object obj in this.Items)
            {
                menu.Items.Add(obj);
            }

            Rectangle controlRect  = control.RectangleToScreen(control.ClientRectangle);
            Rectangle screenBounds = Screen.FromControl(control).WorkingArea;
            int       menuHeight   = menu.Height;

            if (controlRect.Bottom + menuHeight < screenBounds.Bottom)
            {
                menu.Location = new Point(controlRect.Left - menu.Padding.Left, controlRect.Bottom);
            }
            else
            {
                menu.Location = new Point(controlRect.Left - menu.Padding.Left, controlRect.Left - menuHeight);
            }

            menu.Show();
            menu.FocusItem(SelectedIndex);

            return(menu);
        }
コード例 #2
0
        public virtual DropdownMenu Show(Rectangle bounds)
        {
            Close();

            menu          = CreateNewMenu();
            menu.Size     = bounds.Size;
            menu.Location = bounds.Location;
            menu.Items.Clear();

            foreach (object obj in this.Items)
            {
                menu.Items.Add(obj);
            }

            menu.Show();
            menu.FocusItem(SelectedIndex);

            return(menu);
        }