Ejemplo n.º 1
0
        private void IniSystemButtons()
        {
            bool isShowMaxButton = _owner.MaximizeBox;
            bool isShowMinButton = _owner.MinimizeBox;

            //Colse
            SystemButton closeBtn = new SystemButton();

            SystemButtonArray[0]  = closeBtn;
            closeBtn.ToolTip      = "关闭";
            closeBtn.NormalImg    = RenderHelper.GetImageFormResourceStream("ControlExs.FormEx.Res.SystemButtons.close_normal.png");
            closeBtn.HighLightImg = RenderHelper.GetImageFormResourceStream("ControlExs.FormEx.Res.SystemButtons.close_highlight.png");
            closeBtn.DownImg      = RenderHelper.GetImageFormResourceStream("ControlExs.FormEx.Res.SystemButtons.close_down.png");
            closeBtn.LocationRect = new Rectangle(
                _owner.Width - closeBtn.NormalImg.Width,
                -1,
                closeBtn.NormalImg.Width,
                closeBtn.NormalImg.Height);
            //注册事件
            closeBtn.OnMouseDownEvent += new MouseDownEventHandler(this.CloseButtonEvent);


            //Max
            SystemButton MaxBtn = new SystemButton();

            SystemButtonArray[1] = MaxBtn;
            MaxBtn.ToolTip       = "最大化";
            if (isShowMaxButton)
            {
                MaxBtn.NormalImg         = RenderHelper.GetImageFormResourceStream("ControlExs.FormEx.Res.SystemButtons.max_normal.png");
                MaxBtn.HighLightImg      = RenderHelper.GetImageFormResourceStream("ControlExs.FormEx.Res.SystemButtons.max_highlight.png");
                MaxBtn.DownImg           = RenderHelper.GetImageFormResourceStream("ControlExs.FormEx.Res.SystemButtons.max_down.png");
                MaxBtn.OnMouseDownEvent += new MouseDownEventHandler(this.MaxButtonEvent);
                MaxBtn.LocationRect      = new Rectangle(
                    closeBtn.LocationRect.X - MaxBtn.NormalImg.Width,
                    -1,
                    MaxBtn.NormalImg.Width,
                    MaxBtn.NormalImg.Height);
            }
            else
            {
                MaxBtn.LocationRect = Rectangle.Empty;
            }

            //Min
            SystemButton minBtn = new SystemButton();

            SystemButtonArray[2] = minBtn;
            minBtn.ToolTip       = "最小化";
            if (!isShowMinButton)
            {
                minBtn.LocationRect = Rectangle.Empty;
                return;
            }

            minBtn.NormalImg         = RenderHelper.GetImageFormResourceStream("ControlExs.FormEx.Res.SystemButtons.min_normal.png");
            minBtn.HighLightImg      = RenderHelper.GetImageFormResourceStream("ControlExs.FormEx.Res.SystemButtons.min_highlight.png");
            minBtn.DownImg           = RenderHelper.GetImageFormResourceStream("ControlExs.FormEx.Res.SystemButtons.min_down.png");
            minBtn.OnMouseDownEvent += new MouseDownEventHandler(this.MinButtonEvent);
            if (isShowMaxButton)
            {
                minBtn.LocationRect = new Rectangle(
                    MaxBtn.LocationRect.X - minBtn.NormalImg.Width,
                    -1,
                    minBtn.NormalImg.Width,
                    minBtn.NormalImg.Height);
            }
            else
            {
                minBtn.LocationRect = new Rectangle(
                    closeBtn.LocationRect.X - minBtn.NormalImg.Width,
                    -1,
                    minBtn.NormalImg.Width,
                    minBtn.NormalImg.Height);
            }
        }
Ejemplo n.º 2
0
        protected override void OnPaint(PaintEventArgs pevent)
        {
            base.OnPaint(pevent);
            Graphics g = pevent.Graphics;

            g.SmoothingMode     = SmoothingMode.AntiAlias;
            g.InterpolationMode = InterpolationMode.HighQualityBilinear;

            Rectangle imageRect, textRect;

            CalculateRect(out imageRect, out textRect);

            if (!Enabled)
            {
                _state = QQControlState.Disabled;
            }
            switch (_state)
            {
            case QQControlState.Normal:

                RenderHelper.DrawImageWithNineRect(
                    g, _normalImg,
                    ClientRectangle,
                    new Rectangle(0, 0, _normalImg.Width, _normalImg.Height));
                break;

            case QQControlState.Highlight:

                RenderHelper.DrawImageWithNineRect(
                    g, _highlightImg,
                    ClientRectangle,
                    new Rectangle(0, 0, _highlightImg.Width, _highlightImg.Height));
                break;

            case QQControlState.Focus:

                RenderHelper.DrawImageWithNineRect(
                    g, _focusImg,
                    ClientRectangle,
                    new Rectangle(0, 0, _focusImg.Width, _focusImg.Height));
                break;

            case QQControlState.Down:
                RenderHelper.DrawImageWithNineRect(
                    g, _downImg,
                    ClientRectangle,
                    new Rectangle(0, 0, _downImg.Width, _downImg.Height));
                break;

            case QQControlState.Disabled:
                DrawDisabledButton(g);
                break;

            default:
                break;
            }

            if (Image != null)
            {
                g.DrawImage(Image, imageRect, 0, 0, Image.Width, Image.Height, GraphicsUnit.Pixel);
            }

            Color textColor = Enabled ? ForeColor : SystemColors.GrayText;

            TextRenderer.DrawText(
                g,
                Text,
                Font,
                textRect,
                textColor,
                GetTextFormatFlags(TextAlign, RightToLeft == RightToLeft.Yes));
        }
Ejemplo n.º 3
0
        protected override void OnPaint(PaintEventArgs e)
        {
            e.Graphics.SmoothingMode     = SmoothingMode.AntiAlias;
            e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;

            //draw BackgroundImage
            if (BackgroundImage != null)
            {
                switch (BackgroundImageLayout)
                {
                case ImageLayout.Stretch:
                case ImageLayout.Zoom:
                    e.Graphics.DrawImage(
                        _formBkg,
                        ClientRectangle,
                        new Rectangle(0, 0, _formBkg.Width, _formBkg.Height),
                        GraphicsUnit.Pixel);
                    break;

                case ImageLayout.Center:
                case ImageLayout.None:
                case ImageLayout.Tile:
                    e.Graphics.DrawImage(
                        _formBkg,
                        ClientRectangle,
                        ClientRectangle,
                        GraphicsUnit.Pixel);
                    break;
                }
            }

            //draw system buttons
            SystemButtonManager.DrawSystemButtons(e.Graphics);

            //draw fringe
            RenderHelper.DrawFormFringe(this, e.Graphics, _formFringe, Radius);

            //draw icon
            if (Icon != null && ShowIcon)
            {
                e.Graphics.DrawIcon(Icon, IconRect);
            }

            //draw text
            if (Text.Length != 0)
            {
                if (TextWithShadow)
                {
                    using (Image textImg = RenderHelper.GetStringImgWithShadowEffect(Text, TextFont, TextForeColor, TextShadowColor, TextShadowWidth))
                    {
                        e.Graphics.DrawImage(textImg, TextRect.Location);
                    }
                }
                else
                {
                    TextRenderer.DrawText(
                        e.Graphics,
                        Text, TextFont,
                        TextRect,
                        TextForeColor,
                        TextFormatFlags.SingleLine | TextFormatFlags.EndEllipsis);
                }
            }
        }
Ejemplo n.º 4
0
        private void WmNcHitTest(ref Message m)  //调整窗体大小
        {
            int   wparam        = m.LParam.ToInt32();
            Point mouseLocation = new Point(RenderHelper.LOWORD(wparam), RenderHelper.HIWORD(wparam));

            mouseLocation = PointToClient(mouseLocation);

            if (WindowState != FormWindowState.Maximized)
            {
                if (CanResize == true)
                {
                    if (mouseLocation.X < 5 && mouseLocation.Y < 5)
                    {
                        m.Result = new IntPtr(Win32.HTTOPLEFT);
                        return;
                    }

                    if (mouseLocation.X > Width - 5 && mouseLocation.Y < 5)
                    {
                        m.Result = new IntPtr(Win32.HTTOPRIGHT);
                        return;
                    }

                    if (mouseLocation.X < 5 && mouseLocation.Y > Height - 5)
                    {
                        m.Result = new IntPtr(Win32.HTBOTTOMLEFT);
                        return;
                    }

                    if (mouseLocation.X > Width - 5 && mouseLocation.Y > Height - 5)
                    {
                        m.Result = new IntPtr(Win32.HTBOTTOMRIGHT);
                        return;
                    }

                    if (mouseLocation.Y < 3)
                    {
                        m.Result = new IntPtr(Win32.HTTOP);
                        return;
                    }

                    if (mouseLocation.Y > Height - 3)
                    {
                        m.Result = new IntPtr(Win32.HTBOTTOM);
                        return;
                    }

                    if (mouseLocation.X < 3)
                    {
                        m.Result = new IntPtr(Win32.HTLEFT);
                        return;
                    }

                    if (mouseLocation.X > Width - 3)
                    {
                        m.Result = new IntPtr(Win32.HTRIGHT);
                        return;
                    }
                }
            }
            m.Result = new IntPtr(Win32.HTCLIENT);
        }
Ejemplo n.º 5
0
 protected override void OnCreateControl()
 {
     base.OnCreateControl();
     RenderHelper.SetFormRoundRectRgn(this, Radius);
 }