示例#1
0
        /// <summary>
        /// This is used to perform any additional tasks when showing the drop-down
        /// </summary>
        public void ShowDropDown()
        {
            if (!hasInitialized)
            {
                this.CreateHandle();
            }

            startIndex = owner.SelectedIndex;

            // Let the drop-down perform any initialization prior to display
            if (ddControl != null)
            {
                ddControl.ShowDropDown();
            }
        }
示例#2
0
        /// <summary>
        /// This is used to size and position the drop-down, perform any additional tasks, and show it
        /// </summary>
        public void ShowDropDown()
        {
            int idx;

            if (!hasInitialized)
            {
                this.CreateHandle();
            }

            startIndex = owner.SelectedIndex;
            dragOffset = Point.Empty;

            // Let the drop-down perform any initialization prior to display
            if (ddControl != null)
            {
                ddControl.ShowDropDown();
            }

            if (this.Width < owner.Width)
            {
                this.Width = owner.Width;
            }

            // Make sure we are within the screen bounds.  Take into account the working area of all screens.
            // Note that in certain setups, the leftmost/uppermost screen(s) may have negative coordinates.
            Rectangle workingArea, screen = new Rectangle();

            foreach (Screen s in Screen.AllScreens)
            {
                workingArea = s.WorkingArea;

                if (workingArea.X < screen.X)
                {
                    screen.X = workingArea.X;
                }

                if (workingArea.Y < screen.Y)
                {
                    screen.Y = workingArea.Y;
                }

                if (Math.Abs(workingArea.X) + workingArea.Width > screen.Width)
                {
                    screen.Width = Math.Abs(workingArea.X) + workingArea.Width;
                }

                if (Math.Abs(workingArea.Y) + workingArea.Height > screen.Height)
                {
                    screen.Height = Math.Abs(workingArea.Y) + workingArea.Height;
                }
            }

            Point pOwner = owner.Parent.PointToScreen(owner.Location);

            pOwner.Y += owner.Height;

            Point p = pOwner;

            if (this.Width > screen.Width)
            {
                this.Width = screen.Width;
            }

            if (this.Height > screen.Height)
            {
                this.Height = screen.Height;
            }

            if (p.X < screen.X)
            {
                p.X = screen.X;
            }

            if (p.Y < screen.Y)
            {
                p.Y = screen.Y;
            }

            if (p.X + this.Width > screen.X + screen.Width)
            {
                p.X = screen.X + screen.Width - this.Width - 1;
            }

            if (p.Y + this.Height > screen.Y + screen.Height)
            {
                p.Y = screen.Y + screen.Height - this.Height - 1;
            }

            // If we are covering the combo box, move the location above the combo box
            if (p.Y < pOwner.Y)
            {
                idx = pOwner.Y - this.Height - owner.Height;

                // If we would go off the top of the screen, figure out whether we would have more rows visible
                // if we moved the form above the combo box or left it where it is at below the combo box and
                // shrink it to fit.
                if (idx < screen.Y)
                {
                    if (this.Height + idx > this.Height - (pOwner.Y - p.Y))
                    {
                        this.Height += idx;
                        idx          = screen.Y;
                    }
                    else
                    {
                        this.Height -= (pOwner.Y - p.Y);
                        idx          = pOwner.Y;
                    }
                }

                p.Y = idx;
            }

            // The first time it's shown, the size may change due to auto-scaling
            Size sz = this.Size;

            this.Location = p;
            this.Show();
            this.BringToFront();

            if (this.Size != sz)
            {
                this.Size = sz;
            }
        }