コード例 #1
0
        protected virtual void AddWindowButton(MetroWindowButton.TipoMetroWindowButton tipo)
        {
            try
            {
                if (MetroWindowButtons == null)
                {
                    MetroWindowButtons = new Dictionary <MetroWindowButton.TipoMetroWindowButton, MetroWindowButton>();
                }

                if (MetroWindowButtons.ContainsKey(tipo))
                {
                    return;
                }

                MetroWindowButton button = new MetroWindowButton();
                button.Parent = this;
                button.MetroWindowButtonType = tipo;
                button.Size = new Size(LarghezzaPulsanti, AltezzaBarraTitolo);

                MetroWindowButtons.Add(tipo, button);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
コード例 #2
0
        protected virtual void RemoveWindowButton(MetroWindowButton.TipoMetroWindowButton tipo)
        {
            try
            {
                if (MetroWindowButtons == null)
                {
                    return;
                }

                MetroWindowButton button = null;

                if (MetroWindowButtons.TryGetValue(tipo, out button))
                {
                    //Controls.Remove(button);
                    MetroWindowButtons.Remove(tipo);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
コード例 #3
0
        protected override void WndProc(ref Message m)
        {
            switch (m.Msg)
            {
            case (int)WinApi.Messages.WM_SYSCOMMAND:
                if (m.WParam.ToInt32() == (int)WinApi.Messages.SC_RESTORE)
                {
                    this.Height = _iStoreHeight;
                }
                else if (m.WParam.ToInt32() == (int)WinApi.Messages.SC_MAXIMIZE)
                {
                    _iStoreHeight = this.Height;
                }
                break;

            case (int)WinApi.Messages.WM_NCLBUTTONDBLCLK:
            case (int)WinApi.Messages.WM_LBUTTONDBLCLK:
                if (!MaximizeBox)
                {
                    return;
                }
                break;

            case (int)WinApi.Messages.WM_NCHITTEST:

                WinApi.HitTest ht = HitTestNCA(m.HWnd, m.WParam, m.LParam);
                if (ht != WinApi.HitTest.HTCLIENT)
                {
                    m.Result = (IntPtr)ht;
                    return;
                }
                break;

            case (int)WinApi.Messages.WM_NCCALCSIZE:
                NCCalcSize(ref m);
                return;

            case (int)WinApi.Messages.WM_NCPAINT:
                NCPaint(ref m);
                return;

            case (int)WinApi.Messages.WM_NCLBUTTONDOWN:
                if (NCMouseLButtonDown(ref m))
                {
                    return;
                }
                break;

            case (int)WinApi.Messages.WM_NCMOUSELEAVE:
                ResetWindowButtons();
                UpdateDisplay();
                break;

            case (int)WinApi.Messages.WM_NCLBUTTONUP:
                if (NCMouseLButtonUp(ref m))
                {
                    return;
                }
                break;

            case (int)WinApi.Messages.WM_SETTEXT:
                base.WndProc(ref m);
                NCPaint(ref m);
                return;

            case (int)WinApi.Messages.WM_ACTIVATE:
                bool active = (m.WParam != IntPtr.Zero);

                if (WindowState == FormWindowState.Minimized)
                {
                    base.WndProc(ref m);
                    return;
                }
                else
                {
                    base.WndProc(ref m);
                    NCPaint(ref m);
                    m.Result = new IntPtr(1);
                    return;
                }
            }

            base.WndProc(ref m);

            if (m.Msg == (int)WinApi.Messages.WM_NCLBUTTONDBLCLK || m.Msg == (int)WinApi.Messages.WM_LBUTTONDBLCLK)
            {
                MetroWindowButton button = new MetroWindowButton();

                if (MetroWindowButtons.TryGetValue(MetroWindowButton.TipoMetroWindowButton.Maximize, out button))
                {
                    button.MetroWindowButtonType = MetroWindowButton.TipoMetroWindowButton.Maximize;
                    UpdateDisplay();
                }
            }
        }