示例#1
0
        private BeforePopupEventArgs OnBeforePopup()
        {
            BeforePopupEventArgs e = new BeforePopupEventArgs();

            if (this.BeforePopup != null)
            {
                this.BeforePopup(this, e);
            }
            return(e);
        }
示例#2
0
        public void OnPopup()
        {
            if (this.HostControl == null)
            {
                return;
            }

            BeforePopupEventArgs e = this.OnBeforePopup();

            if (e.Cancel)
            {
                return;
            }

            this.HostControl.Show(this);
        }
        public void Show(Control control, Rectangle rect, bool center)
        {
            BeforePopupEventArgs e = this.OnBeforePopup();

            if (e.Cancel)
            {
                return;
            }

            if (control == null)
            {
                throw new ArgumentNullException("control");
            }

            SetOwnerItem(control);

            if (_canResize && !_changeRegion)
            {
                Padding = new Padding(3);
            }
            else if (!_changeRegion)
            {
                Padding = new Padding(1);
            }
            else
            {
                Padding = Padding.Empty;
            }

            int width  = Padding.Horizontal;
            int height = Padding.Vertical;

            base.Size = new Size(
                _popupControl.Width + width,
                _popupControl.Height + height);

            _resizableTop  = false;
            _resizableLeft = false;
            Point location = control.PointToScreen(
                new Point(rect.Left, rect.Bottom));
            Rectangle screen = Screen.FromControl(control).WorkingArea;

            if (center)
            {
                if (location.X + (rect.Width + Size.Width) / 2 > screen.Right)
                {
                    location.X     = screen.Right - Size.Width;
                    _resizableLeft = true;
                }
                else
                {
                    location.X = location.X - (Size.Width - rect.Width) / 2;
                }
            }
            else
            {
                if (location.X + Size.Width > (screen.Left + screen.Width))
                {
                    _resizableLeft = true;
                    location.X     = (screen.Left + screen.Width) - Size.Width;
                }
            }

            if (location.Y + Size.Height > (screen.Top + screen.Height))
            {
                _resizableTop = true;
                location.Y   -= Size.Height + rect.Height;
            }

            location = control.PointToClient(location);
            Show(control, location, ToolStripDropDownDirection.BelowRight);
        }