private void button1_Click(object sender, System.EventArgs e)
 {
     this.colorform = new ColorSelectorLarge();
     this.colorform.Color = this.Color;
     var popup = new Popup(this.colorform, this);
     popup.AnimationSpeed = 0;
     popup.DropDownClosed += this.popup_DropDownClosed;
     popup.Show();
 }
示例#2
0
            public PopupForm(Popup popup)
            {
                this.mPopup = popup;
                this.SetStyle(ControlStyles.ResizeRedraw, true);
                this.FormBorderStyle = FormBorderStyle.None;
                this.StartPosition = FormStartPosition.Manual;
                this.ShowInTaskbar = false;
                this.DockPadding.All = PopupForm.BORDER_MARGIN;
                this.mControlSize = this.mPopup.UserControl.Size;
                this.mPopup.UserControl.Dock = DockStyle.Fill;
                this.Controls.Add(this.mPopup.UserControl);
                this.mWindowSize.Width = this.mControlSize.Width + 2*PopupForm.BORDER_MARGIN;
                this.mWindowSize.Height = this.mControlSize.Height + 2*PopupForm.BORDER_MARGIN;
                this.Opacity = popup.Opacity;

                //These are here to suppress warnings.
                this.DropDown += this.DoNothing;
                this.DropDownClosed += this.DoNothing;

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

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

                    this.mResizingPanel.MouseUp += this.mResizingPanel_MouseUp;
                    this.mResizingPanel.MouseDown += this.mResizingPanel_MouseDown;
                    this.mResizingPanel.MouseMove += this.mResizingPanel_MouseMove;
                }
                this.mPlacement = this.mPopup.HorizontalPlacement;

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

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

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

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

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

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

                // Initialize the animation
                this.mProgress = 0;
                if (this.mPopup.AnimationSpeed > 0)
                {
                    this.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
                    this.mTimer.Interval = 1000/25;
                    this.mTimerStarted = System.DateTimeOffset.Now;
                    this.mTimer.Tick += this.Showing;
                    this.mTimer.Start();
                    this.Showing(null, null);
                }
                else
                {
                    this.SetFinalLocation();
                }

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