Ejemplo n.º 1
0
        internal void RenderButton(
            Graphics g,
            Rectangle rect,
            Color baseColor,
            Color borderColor,
            Color arrowColor,
            ArrowDirection direction)
        {
            CornerRadius cr = new CornerRadius();

            switch (direction)
            {
            case ArrowDirection.Left:
                cr = new CornerRadius(2, 0, 2, 0);
                break;

            case ArrowDirection.Right:
                cr = new CornerRadius(0, 2, 0, 2);
                break;
            }

            RoundRectangle roundRect = new RoundRectangle(rect, cr);

            GDIHelper.FillPath(g, roundRect, baseColor, baseColor);
            GDIHelper.DrawPathBorder(g, roundRect);
            using (SolidBrush brush = new SolidBrush(arrowColor))
            {
                RenderArrowInternal(
                    g,
                    rect,
                    direction,
                    brush);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 绘制背景和边框等
        /// </summary>
        /// <param name="g">The Graphics.</param>
        /// User:Ryan  CreateTime:2011-08-01 16:47.
        private void DrawBackGround(Graphics g)
        {
            GDIHelper.InitializeGraphics(g);
            Rectangle      rect      = new Rectangle(1, 1, this.Width - 3, this.Height - 3);
            RoundRectangle roundRect = new RoundRectangle(rect, new Model.CornerRadius(this._CornerRadius));

            switch (this._ControlState)
            {
            case EnumControlState.Default:
                if (this.FlatStyle != FlatStyle.Flat)
                {
                    GDIHelper.FillRectangle(g, roundRect, SkinManager.CurrentSkin.DefaultControlColor);
                    GDIHelper.DrawPathBorder(g, roundRect);
                }
                break;

            case EnumControlState.HeightLight:
                GDIHelper.FillRectangle(g, roundRect, SkinManager.CurrentSkin.HeightLightControlColor);
                GDIHelper.DrawPathBorder(g, roundRect);
                break;

            case EnumControlState.Focused:
                GDIHelper.FillRectangle(g, roundRect, SkinManager.CurrentSkin.FocusedControlColor);
                GDIHelper.DrawPathBorder(g, roundRect);
                GDIHelper.DrawPathInnerBorder(g, roundRect);
                break;
            }
        }
Ejemplo n.º 3
0
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            int      w = this.BorderWidth > 0 ? this.BorderWidth : 0;
            Graphics g = e.Graphics;

            //缓冲
            //BufferedGraphicsContext currentContext = BufferedGraphicsManager.Current;
            //BufferedGraphics myBuffer = currentContext.Allocate(e.Graphics, e.ClipRectangle);
            //Graphics g = myBuffer.Graphics;

            GDIHelper.InitializeGraphics(g);
            GradientColor  color     = new GradientColor(this._BackBeginColor, this._BackEndColor, null, null);
            Rectangle      rect      = new Rectangle(0, 0, this.Size.Width - 1, this.Size.Height - 1);
            RoundRectangle roundRect = new RoundRectangle(rect, new CornerRadius(this._CornerRadius));

            GDIHelper.FillRectangle(g, roundRect, color);
            if (this._BorderWidth > 0)
            {
                rect.X     += this._BorderWidth - 1; rect.Y += this._BorderWidth - 1;
                rect.Width -= this._BorderWidth - 1; rect.Height -= this._BorderWidth - 1;

                GDIHelper.DrawPathBorder(g, new RoundRectangle(rect, new CornerRadius(this._CornerRadius)), this._BorderColor, this.BorderWidth);
                // 上容器的边框
                Rectangle rectPanel1 = new Rectangle(0, 0, this.Panel1.Width - 1, this.Panel1.Height - 1);
                GDIHelper.DrawPathBorder(g, new RoundRectangle(rectPanel1, new CornerRadius(0)), this._BorderColor, this.BorderWidth);
            }

            //g.SmoothingMode = SmoothingMode.HighQuality;
            //g.PixelOffsetMode = PixelOffsetMode.HighSpeed;
            //myBuffer.Render(e.Graphics);
            //g.Dispose();
            //myBuffer.Dispose();//释放资源
        }
Ejemplo n.º 4
0
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            Graphics  g    = e.Graphics;
            Rectangle rect = new Rectangle(0, 0, this.Width - 1, this.Height - 1);

            rect.Inflate(-1, -1);
            GDIHelper.InitializeGraphics(g);
            GDIHelper.DrawPathBorder(g, new RoundRectangle(rect, this._CornerRadius), this._BorderColor);
            if (this._ControlState == EnumControlState.HeightLight)
            {
                GDIHelper.DrawPathOuterBorder(g, new RoundRectangle(rect, this._CornerRadius), this._HeightLightBolorColor);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 绘制默认边框
        /// </summary>
        /// User:K.Anding  CreateTime:2011-7-30 22:30.
        private void DrawDefaultBorder(Graphics g, Rectangle textRect)
        {
            Rectangle rect = new Rectangle();

            rect.X      = 0;
            rect.Y      = textRect.Height / 2;
            rect.Height = this.Height - textRect.Height / 2 - 1;
            rect.Width  = this.Width - 1;
            RoundRectangle roundRect = new RoundRectangle(rect, new CornerRadius(this._CornerRadius));

            g.SetClip(textRect, CombineMode.Exclude);
            GDIHelper.DrawPathBorder(g, roundRect, this._BorderColor, this._BorderWidth);
            g.ResetClip();
        }
Ejemplo n.º 6
0
        protected override void OnRenderDropDownButtonBackground(ToolStripItemRenderEventArgs e)
        {
            ToolStripItem item = e.Item;
            Graphics      g    = e.Graphics;

            GDIHelper.InitializeGraphics(g);
            Rectangle      rect      = new Rectangle(0, 0, item.Width - 1, item.Height - 1);
            RoundRectangle roundRect = new RoundRectangle(rect, this.ItemCornerRadius);

            if (item.Selected || item.Pressed)
            {
                GDIHelper.FillRectangle(g, roundRect, SkinManager.CurrentSkin.HeightLightControlColor);
                GDIHelper.DrawPathBorder(g, roundRect);
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 绘制下拉框区域.
        /// </summary>
        /// <param name="g">The Graphics.</param>
        /// User:Ryan  CreateTime:2011-07-29 15:44.
        private void DrawComboBox(Graphics g)
        {
            GDIHelper.InitializeGraphics(g);
            Rectangle rect = new Rectangle(Point.Empty, this.Size);

            rect.Width--; rect.Height--;
            ////背景
            RoundRectangle roundRect = new RoundRectangle(rect, 0);
            Color          backColor = this.Enabled ? this._BackColor : SystemColors.Control;

            g.SetClip(this.EditRect, CombineMode.Exclude);
            GDIHelper.FillRectangle(g, roundRect, backColor);
            g.ResetClip();
            this.DrawButton(g);
            GDIHelper.DrawPathBorder(g, roundRect);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// 绘制复选框和内容.
        /// </summary>
        /// <param name="g">The Graphics.</param>
        /// User:Ryan  CreateTime:2011-07-29 15:44.
        private void DrawContent(Graphics g)
        {
            GDIHelper.InitializeGraphics(g);
            int       w        = this.Width;
            int       h        = this.Height;
            Rectangle boxRect  = new Rectangle(this._Margin, h / 2 - this._BoxSize.Height / 2, this._BoxSize.Width, this._BoxSize.Height);
            Size      textSize = g.MeasureString(this.Text, this.Font).ToSize();
            Rectangle textRect = new Rectangle();

            textRect.X      = boxRect.Right + this._Margin;
            textRect.Y      = this._Margin;
            textRect.Height = this.Height - this._Margin * 2;
            textRect.Width  = textSize.Width;
            RoundRectangle roundRect = new RoundRectangle(boxRect, this._CornerRadius);

            switch (this._ControlState)
            {
            case EnumControlState.HeightLight:
                //GDIHelper.DrawPathOuterBorder(g, roundRect, SkinManager.CurrentSkin.OuterBorderColor);
                GDIHelper.DrawPathBorder(g, roundRect, SkinManager.CurrentSkin.OuterBorderColor);
                GDIHelper.DrawPathInnerBorder(g, roundRect, SkinManager.CurrentSkin.HeightLightControlColor.First);
                break;

            default:
                GDIHelper.DrawCheckBox(g, roundRect);
                break;
            }

            Color c = base.Enabled ? this.ForeColor : SkinManager.CurrentSkin.UselessColor;

            //TextRenderer.DrawText(g, this.Text, this.Font, textRect, c, TextFormatFlags.Default);
            GDIHelper.DrawImageAndString(g, textRect, null, Size.Empty, this.Text, this.Font, c);
            switch (this.CheckState)
            {
            case System.Windows.Forms.CheckState.Checked:
                GDIHelper.DrawCheckedStateByImage(g, boxRect);
                break;

            case System.Windows.Forms.CheckState.Indeterminate:
                Rectangle innerRect = boxRect;
                innerRect.Inflate(-3, -3);
                Color cc = Color.FromArgb(46, 117, 35);
                GDIHelper.FillRectangle(g, new RoundRectangle(innerRect, this._CornerRadius), cc);
                break;
            }
        }
Ejemplo n.º 9
0
        private void DrawBorder(Graphics g)
        {
            GDIHelper.InitializeGraphics(g);
            Rectangle      rect      = new Rectangle(1, 1, this.Width - 3, this.Height - 3);
            RoundRectangle roundRect = new RoundRectangle(rect, this._CornerRadius);
            Color          c         = (!this._TextBox.Enabled || this._TextBox.ReadOnly) ? Color.FromArgb(215, 250, 243) : Color.White;

            this._TextBox.BackColor = c;
            //this._TextBox.Font = this._Font;
            //this._TextBox.ForeColor = this._ForeColor;
            GDIHelper.FillPath(g, roundRect, c, c);
            GDIHelper.DrawPathBorder(g, roundRect, this._BorderColor);
            if (this._ControlState == EnumControlState.HeightLight)
            {
                GDIHelper.DrawPathBorder(g, roundRect, SkinManager.CurrentSkin.HeightLightControlColor.Second);
                GDIHelper.DrawPathOuterBorder(g, roundRect, SkinManager.CurrentSkin.HeightLightControlColor.First);
            }
        }
Ejemplo n.º 10
0
        protected override void OnRenderButtonBackground(ToolStripItemRenderEventArgs e)
        {
            ToolStripItem item = e.Item;
            Graphics      g    = e.Graphics;

            GDIHelper.InitializeGraphics(g);
            ////你真没救了!好吧,我承认我是个具有文艺气质的2B程序员
            if (item.Tag != null && item.Tag.Equals("Vicky"))
            {
                int       temp = item.Width >= item.Height ? item.Height : item.Width;
                Rectangle rect = new Rectangle(0, 0, temp, temp);
                rect.Inflate(-1, -1);
                Color c1 = Color.Empty, c2 = Color.Empty, c3 = Color.FromArgb(255, 220, 102);
                Blend blend = new Blend();
                blend.Positions = new float[] { 0f, 0.5f, 1f };
                blend.Factors   = new float[] { 0.25f, 0.75f, 1f };
                Color borderColor = item.Selected || item.Pressed ? Color.FromArgb(24, 116, 205) :
                                    SkinManager.CurrentSkin.BorderColor;
                float w = 1.0F;
                g.PixelOffsetMode = PixelOffsetMode.HighQuality;
                if (item.Selected || item.Pressed)
                {
                    w  = 2.0F;
                    c1 = Color.FromArgb(255, 226, 48);
                    c2 = Color.FromArgb(255, 220, 102);
                    GDIHelper.DrawCrystalButton(g, rect, c1, c2, c3, blend);
                }

                using (Pen p = new Pen(borderColor, w))
                {
                    g.DrawEllipse(p, rect);
                }
            }
            else
            {
                Rectangle      rect      = new Rectangle(1, 1, item.Width - 4, item.Height - 3);
                RoundRectangle roundRect = new RoundRectangle(rect, this.ItemCornerRadius);
                if (item.Selected || item.Pressed)
                {
                    GDIHelper.FillRectangle(g, roundRect, SkinManager.CurrentSkin.HeightLightControlColor);
                    GDIHelper.DrawPathBorder(g, roundRect);
                }
            }
        }
Ejemplo n.º 11
0
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            int      w = this.BorderWidth > 0 ? this.BorderWidth : 0;
            Graphics g = e.Graphics;

            GDIHelper.InitializeGraphics(g);
            GradientColor  color     = new GradientColor(this._BackBeginColor, this._BackEndColor, null, null);
            Rectangle      rect      = new Rectangle(0, 0, this.Size.Width - 1, this.Size.Height - 1);
            RoundRectangle roundRect = new RoundRectangle(rect, new CornerRadius(this._CornerRadius));

            GDIHelper.FillRectangle(g, roundRect, color);
            if (this._BorderWidth > 0)
            {
                rect.X     += this._BorderWidth - 1; rect.Y += this._BorderWidth - 1;
                rect.Width -= this._BorderWidth - 1; rect.Height -= this._BorderWidth - 1;
                GDIHelper.DrawPathBorder(g, new RoundRectangle(rect, new CornerRadius(this._CornerRadius)), this._BorderColor, this.BorderWidth);
            }
        }
Ejemplo n.º 12
0
        protected override void OnDrawColumnHeader(DrawListViewColumnHeaderEventArgs e)
        {
            base.OnDrawColumnHeader(e);
            Graphics g = e.Graphics;

            GDIHelper.InitializeGraphics(g);
            Rectangle bounds = e.Bounds;

            GDIHelper.FillPath(g, new RoundRectangle(bounds, 0), this._HeaderBeginColor, this._HeaderEndColor);
            bounds.Height--;
            if (this.BorderStyle != BorderStyle.None)
            {
                using (Pen p = new Pen(this.BorderColor))
                {
                    g.DrawLine(p, new Point(bounds.Right, bounds.Bottom), new Point(bounds.Right, bounds.Top));
                    g.DrawLine(p, new Point(bounds.Left, bounds.Bottom), new Point(bounds.Right, bounds.Bottom));
                }
            }
            else
            {
                GDIHelper.DrawPathBorder(g, new RoundRectangle(bounds, 0), this._BorderColor);
            }

            bounds.Height++;
            TextFormatFlags flags    = GetFormatFlags(e.Header.TextAlign);
            Rectangle       textRect = new Rectangle(
                bounds.X + 3,
                bounds.Y,
                bounds.Width - 6,
                bounds.Height);;
            Image     image     = null;
            Size      imgSize   = new System.Drawing.Size(16, 16);
            Rectangle imageRect = Rectangle.Empty;

            if (e.Header.ImageList != null)
            {
                image = e.Header.ImageIndex == -1 ?
                        null : e.Header.ImageList.Images[e.Header.ImageIndex];
            }

            GDIHelper.DrawImageAndString(g, bounds, image, imgSize, e.Header.Text, this._Font, e.ForeColor);
        }
Ejemplo n.º 13
0
        protected override void OnRenderToolStripBorder(ToolStripRenderEventArgs e)
        {
            ToolStrip toolStrip = e.ToolStrip;
            Graphics  g         = e.Graphics;

            GDIHelper.InitializeGraphics(g);
            Rectangle rect = e.AffectedBounds;

            if (toolStrip is ToolStripDropDown)
            {
                ////阴影边框
                rect.Width--; rect.Height--;
                CornerRadius   toolStripCornerRadius = new CornerRadius(this.MenuCornerRadius);
                RoundRectangle roundRect             = new RoundRectangle(rect, toolStripCornerRadius);
                GDIHelper.DrawPathBorder(g, roundRect, this.MenuBorderColor);
            }
            else
            {
                base.OnRenderToolStripBorder(e);
            }
        }
Ejemplo n.º 14
0
        protected override void WndProc(ref Message m)
        {
            base.WndProc(ref m);
            switch (m.Msg)
            {
            case (int)WindowMessages.WM_PAINT:
                if (this.BorderWidth > 0)
                {
                    using (Graphics g = Graphics.FromHwnd(m.HWnd))
                    {
                        Rectangle rect = new Rectangle(0, 0, this.Width - 1, this.Height - 1);
                        GDIHelper.DrawPathBorder(g, new RoundRectangle(rect, 0), this._BorderColor, this.BorderWidth);
                    }
                }
                break;

            case (int)WindowMessages.WM_VSCROLL:
            case (int)WindowMessages.WM_HSCROLL:
                this.Invalidate(true);
                break;
            }
        }
Ejemplo n.º 15
0
 protected override void WndProc(ref Message m)
 {
     base.WndProc(ref m);
     switch (m.Msg)
     {
     case (int)WindowMessages.WM_PAINT:
     case (int)WindowMessages.WM_WINDOWPOSCHANGED:
         IntPtr hdc = Win32.GetDC(m.HWnd);
         try
         {
             using (Graphics g = Graphics.FromHdc(hdc))
             {
                 Rectangle bounds = _owner.HeaderEndRect();
                 GDIHelper.InitializeGraphics(g);
                 GDIHelper.FillPath(g, new RoundRectangle(bounds, 0), this._owner._HeaderBeginColor, this._owner._HeaderEndColor);
                 bounds.Width--; bounds.Height--;
                 if (this._owner.BorderStyle != BorderStyle.None)
                 {
                     using (Pen p = new Pen(this._owner.BorderColor))
                     {
                         g.DrawLine(p, new Point(bounds.Left, bounds.Bottom), new Point(bounds.Left, bounds.Top));
                         g.DrawLine(p, new Point(bounds.Right, bounds.Bottom), new Point(bounds.Right, bounds.Top));
                         g.DrawLine(p, new Point(bounds.Left, bounds.Bottom), new Point(bounds.Right, bounds.Bottom));
                     }
                 }
                 else
                 {
                     GDIHelper.DrawPathBorder(g, new RoundRectangle(bounds, 0), this._owner._BorderColor);
                 }
             }
         }
         finally
         {
             Win32.ReleaseDC(m.HWnd, hdc);
         }
         break;
     }
 }
Ejemplo n.º 16
0
        private void NcPaint(ref Message msg)
        {
            if (base.BorderStyle == BorderStyle.None)
            {
                return;
            }

            IntPtr hDC = Win32.GetWindowDC(msg.HWnd);

            if (hDC == IntPtr.Zero)
            {
                throw new Win32Exception();
            }

            Rectangle bounds = new Rectangle(0, 0, Width - 1, Height - 1);

            using (Graphics g = Graphics.FromHdc(hDC))
            {
                GDIHelper.DrawPathBorder(g, new RoundRectangle(bounds, 0), this._BorderColor);
            }
            msg.Result = IntPtr.Zero;
            Win32.ReleaseDC(msg.HWnd, hDC);
        }
Ejemplo n.º 17
0
        private void DrawTabPages(Graphics g)
        {
            Rectangle tabRect;
            Point     cusorPoint = PointToClient(MousePosition);
            bool      hover;
            bool      selected;
            bool      hasSetClip      = false;
            bool      alignHorizontal =
                (Alignment == TabAlignment.Top ||
                 Alignment == TabAlignment.Bottom);
            LinearGradientMode mode = alignHorizontal ?
                                      LinearGradientMode.Vertical : LinearGradientMode.Horizontal;

            if (alignHorizontal)
            {
                IntPtr upDownButtonHandle = UpDownButtonHandle;
                bool   hasUpDown          = upDownButtonHandle != IntPtr.Zero;
                if (hasUpDown)
                {
                    if (Win32.IsWindowVisible(upDownButtonHandle))
                    {
                        RECT upDownButtonRect = new RECT();
                        Win32.GetWindowRect(
                            upDownButtonHandle, ref upDownButtonRect);
                        Rectangle upDownRect = Rectangle.FromLTRB(
                            upDownButtonRect.left,
                            upDownButtonRect.top,
                            upDownButtonRect.right,
                            upDownButtonRect.bottom);
                        upDownRect = RectangleToClient(upDownRect);

                        switch (Alignment)
                        {
                        case TabAlignment.Top:
                            upDownRect.Y = 0;
                            break;

                        case TabAlignment.Bottom:
                            upDownRect.Y =
                                ClientRectangle.Height - DisplayRectangle.Height;
                            break;
                        }
                        upDownRect.Height = ClientRectangle.Height;
                        g.SetClip(upDownRect, CombineMode.Exclude);
                        hasSetClip = true;
                    }
                }
            }

            for (int index = 0; index < base.TabCount; index++)
            {
                TabPage page = TabPages[index];
                tabRect  = GetTabRect(index);
                hover    = tabRect.Contains(cusorPoint);
                selected = SelectedIndex == index;
                Color baseColor   = _BaseTabolor;
                Color borderColor = _BorderColor;
                Blend blend       = new Blend();
                blend.Positions = new float[] { 0f, 0.3f, 0.5f, 0.7f, 1.0f };
                blend.Factors   = new float[] { 0.1f, 0.3f, 0.5f, 0.8f, 1.0f };
                if (selected)
                {
                    baseColor = this._CheckedTabColor;
                }
                else if (hover)
                {
                    baseColor       = this._HeightLightTabColor;
                    blend.Positions = new float[] { 0f, 0.3f, 0.6f, 0.8f, 1f };
                    blend.Factors   = new float[] { .2f, 0.4f, 0.6f, 0.5f, .4f };
                }
                Rectangle exRect = new Rectangle(tabRect.Left, tabRect.Bottom, tabRect.Width, 1);
                g.SetClip(exRect, CombineMode.Exclude);
                CornerRadius cr = new CornerRadius(this._TabCornerRadius, this._TabCornerRadius, 0, 0);
                tabRect.X += this._TabMargin; tabRect.Width -= this._TabMargin;
                tabRect.Y++;
                tabRect.Height--;
                RoundRectangle roundRect = new RoundRectangle(tabRect, cr);
                GDIHelper.InitializeGraphics(g);
                switch (this._TabStyle)
                {
                case EnumTabStyle.AnglesWing:
                    cr         = new CornerRadius(this._TabCornerRadius);
                    tabRect.X += this._TabCornerRadius; tabRect.Width -= this._TabCornerRadius * 2;
                    roundRect  = new RoundRectangle(tabRect, cr);
                    using (GraphicsPath path = roundRect.ToGraphicsAnglesWingPath())
                    {
                        using (LinearGradientBrush brush = new LinearGradientBrush(roundRect.Rect, baseColor, this._BackColor, LinearGradientMode.Vertical))
                        {
                            brush.Blend = blend;
                            g.FillPath(brush, path);
                        }
                    }
                    using (GraphicsPath path = roundRect.ToGraphicsAnglesWingPath())
                    {
                        using (Pen pen = new Pen(this._BorderColor, 1))
                        {
                            g.DrawPath(pen, path);
                        }
                    }
                    break;

                case EnumTabStyle.Default:
                    GDIHelper.FillPath(g, roundRect, baseColor, this._BackColor, blend);
                    GDIHelper.DrawPathBorder(g, roundRect, this._BorderColor);
                    break;
                }

                g.ResetClip();
                if (this.Alignment == TabAlignment.Top)
                {
                    Image img     = null;
                    Size  imgSize = Size.Empty;
                    if (this.ImageList != null && page.ImageIndex >= 0)
                    {
                        img     = this.ImageList.Images[page.ImageIndex];
                        imgSize = img.Size;
                    }

                    GDIHelper.DrawImageAndString(g, tabRect, img, imgSize, page.Text, this._CaptionFont, this._CaptionForceColor);
                }
                else
                {
                    bool hasImage = DrawTabImage(g, page, tabRect);
                    DrawtabText(g, page, tabRect, hasImage);
                }
            }
            if (hasSetClip)
            {
                g.ResetClip();
            }
        }