Пример #1
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;
            }
        }
Пример #2
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);
        }
Пример #3
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();
            }
        }