Ejemplo n.º 1
0
        public bool ShowPopup(Control popupControl)
        {
            if (_popupForm == null || _popupForm.IsDisposed || _popupForm.Disposing)
            {
                if (_hostControl != null)
                {
                    if (object.ReferenceEquals(_hostControl, popupControl))
                    {
                        throw new InvalidOperationException(Resources.InvalidOperation_PopupSameControl);
                    }

                    FormMessageFilter msgFilter = new FormMessageFilter(_hostControl);
                    msgFilter.HostClosed += delegate
                    {
                        this.ClosePopup();
                    };

                    _popupForm = new PopupForm(this.ServiceProvider);
                    _popupForm.FormBorderStyle = this.PopupBorderStyle;
                    _popupForm.FormClosing    += delegate
                    {
                        this.PopupSize = _popupForm.Size;
                        this.OnPopupClosing(EventArgs.Empty);
                    };
                    _popupForm.Disposed += delegate
                    {
                        msgFilter.ReleaseHandle();
                        msgFilter = null;
                    };

                    Control   parentControl = _hostControl.Parent;
                    Rectangle hostBounds    = new Rectangle(new Point(0, 0), this.PopupSize);

                    if (parentControl != null)
                    {
                        Rectangle hostControlBounds = parentControl.RectangleToScreen(_hostControl.Bounds);
                        hostBounds.X = hostControlBounds.Left;
                        hostBounds.Y = hostControlBounds.Bottom;
                    }

                    if (popupControl != null)
                    {
                        popupControl.Parent = _popupForm;
                        popupControl.Dock   = DockStyle.Fill;
                    }

                    _popupForm.Bounds = hostBounds;
                    _popupForm.Show();

                    return(true);
                }
            }

            return(false);
        }
Ejemplo n.º 2
0
		public bool ShowPopup(Control popupControl)
		{
			if (_popupForm == null || _popupForm.IsDisposed || _popupForm.Disposing)
			{
				if (_hostControl != null)
				{
					if (object.ReferenceEquals(_hostControl, popupControl))
					{
						throw new InvalidOperationException(Resources.InvalidOperation_PopupSameControl);
					}

					FormMessageFilter msgFilter = new FormMessageFilter(_hostControl);
					msgFilter.HostClosed += delegate
					{
						this.ClosePopup();
					};

					_popupForm = new PopupForm(this.ServiceProvider);
					_popupForm.FormBorderStyle = this.PopupBorderStyle;
					_popupForm.FormClosing += delegate
					{
						this.PopupSize = _popupForm.Size;
						this.OnPopupClosing(EventArgs.Empty);
					};
					_popupForm.Disposed += delegate
					{
						msgFilter.ReleaseHandle();
						msgFilter = null;
					};

					Control parentControl = _hostControl.Parent;
					Rectangle hostBounds = new Rectangle(new Point(0, 0), this.PopupSize);

					if (parentControl != null)
					{
						Rectangle hostControlBounds = parentControl.RectangleToScreen(_hostControl.Bounds);
						hostBounds.X = hostControlBounds.Left;
						hostBounds.Y = hostControlBounds.Bottom;
					}

					if (popupControl != null)
					{
						popupControl.Parent = _popupForm;
						popupControl.Dock = DockStyle.Fill;
					}

					_popupForm.Bounds = hostBounds;
					_popupForm.Show();

					return true;
				}
			}

			return false;
		}