Ejemplo n.º 1
0
            public PopupForm(Popup popup)
            {
                mPopup = popup;
                SetStyle(ControlStyles.ResizeRedraw, true);
                FormBorderStyle          = FormBorderStyle.None;
                StartPosition            = FormStartPosition.Manual;
                this.ShowInTaskbar       = false;
                this.DockPadding.All     = BORDER_MARGIN;
                mControlSize             = mPopup.mUserControl.Size;
                mPopup.mUserControl.Dock = DockStyle.Fill;
                Controls.Add(mPopup.mUserControl);
                mWindowSize.Width  = mControlSize.Width + 2 * BORDER_MARGIN;
                mWindowSize.Height = mControlSize.Height + 2 * BORDER_MARGIN;
                this.Opacity       = popup.mOpacity;

                //These are here to suppress warnings.
                this.DropDown       += new System.EventHandler(DoNothing);
                this.DropDownClosed += new System.EventHandler(DoNothing);

                Form parentForm = mPopup.mParent.FindForm();

                if (parentForm != null)
                {
                    parentForm.AddOwnedForm(this);
                }

                if (mPopup.mResizable)
                {
                    mResizingPanel = new Panel();
                    if (mBackgroundImage == null)
                    {
                        var resources = new System.Resources.ResourceManager(typeof(Popup));
                        mBackgroundImage = (System.Drawing.Image)resources.GetObject("CornerPicture.Image");
                    }
                    mResizingPanel.BackgroundImage = mBackgroundImage;
                    mResizingPanel.Width           = 12;
                    mResizingPanel.Height          = 12;
                    mResizingPanel.BackColor       = Color.Red;
                    mResizingPanel.Left            = mPopup.mUserControl.Width - 15;
                    mResizingPanel.Top             = mPopup.mUserControl.Height - 15;
                    mResizingPanel.Cursor          = Cursors.SizeNWSE;
                    mResizingPanel.Anchor          = AnchorStyles.Bottom | AnchorStyles.Right;
                    mResizingPanel.Parent          = this;
                    mResizingPanel.BringToFront();

                    this.mResizingPanel.MouseUp   += new MouseEventHandler(mResizingPanel_MouseUp);
                    this.mResizingPanel.MouseDown += new MouseEventHandler(mResizingPanel_MouseDown);
                    this.mResizingPanel.MouseMove += new MouseEventHandler(mResizingPanel_MouseMove);
                }
                mPlacement = mPopup.mPlacement;

                // Try to place the popup at the asked location
                ReLocate();

                // Check if the form is out of the screen
                // And if yes try to adapt the placement
                Rectangle workingArea = Screen.FromControl(mPopup.mParent).WorkingArea;

                if (mNormalPos.X + this.Width > workingArea.Right)
                {
                    if ((mPlacement & ePlacement.Right) != 0)
                    {
                        mPlacement = (mPlacement & ~ePlacement.Right) | ePlacement.Left;
                    }
                }
                else
                {
                    if (mNormalPos.X < workingArea.Left)
                    {
                        if ((mPlacement & ePlacement.Left) != 0)
                        {
                            mPlacement = (mPlacement & ~ePlacement.Left) | ePlacement.Right;
                        }
                    }
                }

                if (mNormalPos.Y + this.Height > workingArea.Bottom)
                {
                    if ((mPlacement & ePlacement.Bottom) != 0)
                    {
                        mPlacement = (mPlacement & ~ePlacement.Bottom) | ePlacement.Top;
                    }
                }
                else
                {
                    if (mNormalPos.Y < workingArea.Top)
                    {
                        if ((mPlacement & ePlacement.Top) != 0)
                        {
                            mPlacement = (mPlacement & ~ePlacement.Top) | ePlacement.Bottom;
                        }
                    }
                }

                if (mPlacement != mPopup.mPlacement)
                {
                    ReLocate();
                }

                // Check if the form is still out of the screen
                // If yes just move it back into the screen without changing Placement
                if (mNormalPos.X + mWindowSize.Width > workingArea.Right)
                {
                    mNormalPos.X = workingArea.Right - mWindowSize.Width;
                }
                else
                {
                    if (mNormalPos.X < workingArea.Left)
                    {
                        mNormalPos.X = workingArea.Left;
                    }
                }

                if (mNormalPos.Y + mWindowSize.Height > workingArea.Bottom)
                {
                    mNormalPos.Y = workingArea.Bottom - mWindowSize.Height;
                }
                else
                {
                    if (mNormalPos.Y < workingArea.Top)
                    {
                        mNormalPos.Y = workingArea.Top;
                    }
                }

                // Initialize the animation
                mProgress = 0;
                if (mPopup.mAnimationSpeed > 0)
                {
                    mTimer = new Timer();

                    // I always aim 25 images per seconds.. seems to be a good value
                    // it looks smooth enough on fast computers and do not drain slower one
                    mTimer.Interval = 1000 / 25;
                    mTimerStarted   = System.DateTimeOffset.Now;
                    mTimer.Tick    += new System.EventHandler(Showing);
                    mTimer.Start();
                    Showing(null, null);
                }
                else
                {
                    SetFinalLocation();
                }

                Show();
                mPopup.OnDropDown(mPopup.mParent, new System.EventArgs());
            }
Ejemplo n.º 2
0
            public PopupForm(Popup popup)
            {
                mPopup = popup;
                SetStyle(ControlStyles.ResizeRedraw, true);
                FormBorderStyle = FormBorderStyle.None;
                StartPosition = FormStartPosition.Manual;
                this.ShowInTaskbar = false;
                this.DockPadding.All = BORDER_MARGIN;
                mControlSize = mPopup.mUserControl.Size;
                mPopup.mUserControl.Dock = DockStyle.Fill;
                Controls.Add(mPopup.mUserControl);
                mWindowSize.Width = mControlSize.Width + 2*BORDER_MARGIN;
                mWindowSize.Height = mControlSize.Height + 2*BORDER_MARGIN;
                this.Opacity = popup.mOpacity;

                //These are here to suppress warnings.
                this.DropDown += new System.EventHandler(DoNothing);
                this.DropDownClosed += new System.EventHandler(DoNothing);

                Form parentForm = mPopup.mParent.FindForm();
                if (parentForm != null)
                {
                    parentForm.AddOwnedForm(this);
                }

                if (mPopup.mResizable)
                {
                    mResizingPanel = new Panel();
                    if (mBackgroundImage == null)
                    {
                        var resources = new System.Resources.ResourceManager(typeof (Popup));
                        mBackgroundImage = (System.Drawing.Image) resources.GetObject("CornerPicture.Image");
                    }
                    mResizingPanel.BackgroundImage = mBackgroundImage;
                    mResizingPanel.Width = 12;
                    mResizingPanel.Height = 12;
                    mResizingPanel.BackColor = Color.Red;
                    mResizingPanel.Left = mPopup.mUserControl.Width - 15;
                    mResizingPanel.Top = mPopup.mUserControl.Height - 15;
                    mResizingPanel.Cursor = Cursors.SizeNWSE;
                    mResizingPanel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
                    mResizingPanel.Parent = this;
                    mResizingPanel.BringToFront();

                    this.mResizingPanel.MouseUp += new MouseEventHandler(mResizingPanel_MouseUp);
                    this.mResizingPanel.MouseDown += new MouseEventHandler(mResizingPanel_MouseDown);
                    this.mResizingPanel.MouseMove += new MouseEventHandler(mResizingPanel_MouseMove);
                }
                mPlacement = mPopup.mPlacement;

                // Try to place the popup at the asked location
                ReLocate();

                // Check if the form is out of the screen
                // And if yes try to adapt the placement
                Rectangle workingArea = Screen.FromControl(mPopup.mParent).WorkingArea;
                if (mNormalPos.X + this.Width > workingArea.Right)
                {
                    if ((mPlacement & ePlacement.Right) != 0)
                    {
                        mPlacement = (mPlacement & ~ePlacement.Right) | ePlacement.Left;
                    }
                }
                else
                {
                    if (mNormalPos.X < workingArea.Left)
                    {
                        if ((mPlacement & ePlacement.Left) != 0)
                        {
                            mPlacement = (mPlacement & ~ePlacement.Left) | ePlacement.Right;
                        }
                    }
                }

                if (mNormalPos.Y + this.Height > workingArea.Bottom)
                {
                    if ((mPlacement & ePlacement.Bottom) != 0)
                    {
                        mPlacement = (mPlacement & ~ePlacement.Bottom) | ePlacement.Top;
                    }
                }
                else
                {
                    if (mNormalPos.Y < workingArea.Top)
                    {
                        if ((mPlacement & ePlacement.Top) != 0)
                        {
                            mPlacement = (mPlacement & ~ePlacement.Top) | ePlacement.Bottom;
                        }
                    }
                }

                if (mPlacement != mPopup.mPlacement)
                {
                    ReLocate();
                }

                // Check if the form is still out of the screen
                // If yes just move it back into the screen without changing Placement
                if (mNormalPos.X + mWindowSize.Width > workingArea.Right)
                {
                    mNormalPos.X = workingArea.Right - mWindowSize.Width;
                }
                else
                {
                    if (mNormalPos.X < workingArea.Left)
                    {
                        mNormalPos.X = workingArea.Left;
                    }
                }

                if (mNormalPos.Y + mWindowSize.Height > workingArea.Bottom)
                {
                    mNormalPos.Y = workingArea.Bottom - mWindowSize.Height;
                }
                else
                {
                    if (mNormalPos.Y < workingArea.Top)
                    {
                        mNormalPos.Y = workingArea.Top;
                    }
                }

                // Initialize the animation
                mProgress = 0;
                if (mPopup.mAnimationSpeed > 0)
                {
                    mTimer = new Timer();

                    // I always aim 25 images per seconds.. seems to be a good value
                    // it looks smooth enough on fast computers and do not drain slower one
                    mTimer.Interval = 1000/25;
                    mTimerStarted = System.DateTimeOffset.Now;
                    mTimer.Tick += new System.EventHandler(Showing);
                    mTimer.Start();
                    Showing(null, null);
                }
                else
                {
                    SetFinalLocation();
                }

                Show();
                mPopup.OnDropDown(mPopup.mParent, new System.EventArgs());
            }