Ejemplo n.º 1
0
        protected override void OnMouseDown(
            System.Windows.Forms.MouseEventArgs e
            )
        {


            if (e.Button == MouseButtons.Left)
            m_bMouseDown = true;
           
        #region Titlebar buttons

        if (m_xTitleBar.ShouldDrawButtonBox)
        {
            foreach (XTitleBarButton xbtn in m_xTitleBar.TitleBarButtons)
            {

                if (m_TitleBarButtonsBox.IsVisible(e.Location))
                {
                    if (PointInRect(
                         e.Location,
                         new Rectangle(
                         xbtn.XButtonLeft,
                         xbtn.XButtonTop,
                         xbtn.XButtonWidth,
                         xbtn.XButtonHeight
                         )))
                    {
                        if (xbtn.XButtonType == XTitleBarButton.XTitleBarButtonType.Minimize)
                            this.WindowState = FormWindowState.Minimized;
                        else if (xbtn.XButtonType == XTitleBarButton.XTitleBarButtonType.Maximize)
                        {
                            if (m_bMaximized)
                            {
                                m_bMaximized = false;
                                this.Size = new Size(m_rcRestoreBounds.Width, m_rcRestoreBounds.Height);
                                this.Location = new Point(m_rcRestoreBounds.Left, m_rcRestoreBounds.Top);
                            }
                            else
                            {
                                m_rcRestoreBounds = new Rectangle(this.Location, this.Size);
                                Rectangle wa = Screen.GetWorkingArea(this);
                                this.Size = new Size(wa.Width, wa.Height);
                                this.Location = new Point(wa.Left, wa.Top);
                                m_bMaximized = true;
                            }
                        }
                        else if (xbtn.XButtonType == XTitleBarButton.XTitleBarButtonType.Close)
                        {
                            Application.Exit();
                        }
                    }
                }

            }
        }
        else
        {
            foreach (XTitleBarButton xbtn in m_xTitleBar.TitleBarButtons)
            {
                if (PointInRect(
                         e.Location,
                         new Rectangle(
                         xbtn.XButtonLeft,
                         xbtn.XButtonTop,
                         xbtn.XButtonWidth,
                         xbtn.XButtonHeight
                         )))
                {
                    if (xbtn.XButtonType == XTitleBarButton.XTitleBarButtonType.Minimize)
                        this.WindowState = FormWindowState.Minimized;
                    else if (xbtn.XButtonType == XTitleBarButton.XTitleBarButtonType.Maximize)
                    {
                        if (m_bMaximized)
                        {
                            m_bMaximized = false;
                            this.Size = new Size(m_rcRestoreBounds.Width, m_rcRestoreBounds.Height);
                            this.Location = new Point(m_rcRestoreBounds.Left, m_rcRestoreBounds.Top);
                        }
                        else
                        {
                            m_rcRestoreBounds = new Rectangle(this.Location, this.Size);
                            Rectangle wa = Screen.GetWorkingArea(this);
                            this.Size = new Size(wa.Width, wa.Height);
                            this.Location = new Point(wa.Left, wa.Top);
                            m_bMaximized = true;
                        }
                    }
                    else if (xbtn.XButtonType == XTitleBarButton.XTitleBarButtonType.Close)
                    {
                        Application.Exit();
                    }
                }


            }
        }
        #endregion

        #region Titlebar icon holder
            // mouse over TitleBarIconHolder :
            if (PointInRect(e.Location, m_rcXTitleBarIconHolder))
            {
                if (e.Button == MouseButtons.Left)
                {
                    // find hovering button:
                    int lIdx = m_xtbHolder.HitTestHolderButton(
                         e.X,
                         e.Y,
                         m_rcXTitleBarIconHolder
                    );

                    for (int i = 0; i < m_xtbHolder.HolderButtons.Count; i++)
                    {
                        if (i == lIdx)
                        {
                            XCoolFormHolderButtonClickArgs XCoolHolderButton =
                                new XCoolFormHolderButtonClickArgs(i);
                            if (XCoolFormHolderButtonClick != null)
                                XCoolFormHolderButtonClick(XCoolHolderButton);
                        }
                    }
                }
            }
            #endregion
          

        }
Ejemplo n.º 2
0
        protected override void OnMouseDown(
            System.Windows.Forms.MouseEventArgs e
            )
        {
            if (e.Button == MouseButtons.Left)
            {
                m_bMouseDown = true;
            }

            #region Titlebar buttons

            if (m_xTitleBar.ShouldDrawButtonBox)
            {
                foreach (XTitleBarButton xbtn in m_xTitleBar.TitleBarButtons)
                {
                    if (m_TitleBarButtonsBox.IsVisible(e.Location))
                    {
                        if (PointInRect(
                                e.Location,
                                new Rectangle(
                                    xbtn.XButtonLeft,
                                    xbtn.XButtonTop,
                                    xbtn.XButtonWidth,
                                    xbtn.XButtonHeight
                                    )))
                        {
                            if (xbtn.XButtonType == XTitleBarButton.XTitleBarButtonType.Minimize)
                            {
                                this.WindowState = FormWindowState.Minimized;
                            }
                            else if (xbtn.XButtonType == XTitleBarButton.XTitleBarButtonType.Maximize)
                            {
                                if (m_bMaximized)
                                {
                                    m_bMaximized  = false;
                                    this.Size     = new Size(m_rcRestoreBounds.Width, m_rcRestoreBounds.Height);
                                    this.Location = new Point(m_rcRestoreBounds.Left, m_rcRestoreBounds.Top);
                                }
                                else
                                {
                                    m_rcRestoreBounds = new Rectangle(this.Location, this.Size);
                                    Rectangle wa = Screen.GetWorkingArea(this);
                                    this.Size     = new Size(wa.Width, wa.Height);
                                    this.Location = new Point(wa.Left, wa.Top);
                                    m_bMaximized  = true;
                                }
                            }
                            else if (xbtn.XButtonType == XTitleBarButton.XTitleBarButtonType.Close)
                            {
                                Application.Exit();
                            }
                        }
                    }
                }
            }
            else
            {
                foreach (XTitleBarButton xbtn in m_xTitleBar.TitleBarButtons)
                {
                    if (PointInRect(
                            e.Location,
                            new Rectangle(
                                xbtn.XButtonLeft,
                                xbtn.XButtonTop,
                                xbtn.XButtonWidth,
                                xbtn.XButtonHeight
                                )))
                    {
                        if (xbtn.XButtonType == XTitleBarButton.XTitleBarButtonType.Minimize)
                        {
                            this.WindowState = FormWindowState.Minimized;
                        }
                        else if (xbtn.XButtonType == XTitleBarButton.XTitleBarButtonType.Maximize)
                        {
                            if (m_bMaximized)
                            {
                                m_bMaximized  = false;
                                this.Size     = new Size(m_rcRestoreBounds.Width, m_rcRestoreBounds.Height);
                                this.Location = new Point(m_rcRestoreBounds.Left, m_rcRestoreBounds.Top);
                            }
                            else
                            {
                                m_rcRestoreBounds = new Rectangle(this.Location, this.Size);
                                Rectangle wa = Screen.GetWorkingArea(this);
                                this.Size     = new Size(wa.Width, wa.Height);
                                this.Location = new Point(wa.Left, wa.Top);
                                m_bMaximized  = true;
                            }
                        }
                        else if (xbtn.XButtonType == XTitleBarButton.XTitleBarButtonType.Close)
                        {
                            Application.Exit();
                        }
                    }
                }
            }
            #endregion

            #region Titlebar icon holder
            // mouse over TitleBarIconHolder :
            if (PointInRect(e.Location, m_rcXTitleBarIconHolder))
            {
                if (e.Button == MouseButtons.Left)
                {
                    // find hovering button:
                    int lIdx = m_xtbHolder.HitTestHolderButton(
                        e.X,
                        e.Y,
                        m_rcXTitleBarIconHolder
                        );

                    for (int i = 0; i < m_xtbHolder.HolderButtons.Count; i++)
                    {
                        if (i == lIdx)
                        {
                            XCoolFormHolderButtonClickArgs XCoolHolderButton =
                                new XCoolFormHolderButtonClickArgs(i);
                            if (XCoolFormHolderButtonClick != null)
                            {
                                XCoolFormHolderButtonClick(XCoolHolderButton);
                            }
                        }
                    }
                }
            }
            #endregion
        }