示例#1
0
        private void RenderText(Graphics g)
        {
            using (TextRenderingHintGraphics textRenderGraphics
                       = new TextRenderingHintGraphics(g))
            {
                PointF point = CalculateRenderTextStartPoint(g);
                Color  fc    = ForeColor;
                Color  bc    = BorderColor;
                if (ForeColorSuit)
                {
                    bool Base = SkinTools.ColorSlantsDarkOrBright(this.Parent.BackColor);
                    if (Base)
                    {
                        fc = Color.White;
                        bc = Color.Black;
                    }
                    else
                    {
                        fc = Color.Black;
                        bc = Color.White;
                    }
                }
                switch (_artTextStyle)
                {
                case ArtTextStyle.Border:
                    RenderBordText(g, point, fc, bc);
                    break;

                case ArtTextStyle.Relievo:
                    RenderRelievoText(g, point, fc, bc);
                    break;

                case ArtTextStyle.Forme:
                    RenderFormeText(g, point, fc, bc);
                    break;

                case ArtTextStyle.Anamorphosis:
                    RenderAnamorphosisText(g, point, fc, bc);
                    break;
                }
            }
        }
        //画标题和ICO
        protected override void OnRenderSkinFormCaption(
            SkinFormCaptionRenderEventArgs e)
        {
            Graphics   g        = e.Graphics;
            Rectangle  rect     = e.ClipRectangle;
            CCSkinMain form     = e.SkinForm;
            Rectangle  iconRect = form.IconRect;
            Rectangle  textRect = Rectangle.Empty;

            bool closeBox    = form.ControlBox;
            bool minimizeBox = form.ControlBox && form.MinimizeBox;
            bool maximizeBox = form.ControlBox && form.MaximizeBox;

            int textWidthDec = 0;

            if (closeBox)
            {
                textWidthDec += form.CloseBoxSize.Width + form.ControlBoxOffset.X;
            }

            if (maximizeBox)
            {
                textWidthDec += form.MaxSize.Width + form.ControlBoxSpace;
            }

            if (minimizeBox)
            {
                textWidthDec += form.MiniSize.Width + form.ControlBoxSpace;
            }

            foreach (CmSysButton item in form.ControlBoxManager.SysButtonItems)
            {
                if (form.ControlBox && item.Visibale)
                {
                    textWidthDec += item.Size.Width + form.ControlBoxSpace;
                }
            }

            textRect = new Rectangle(
                iconRect.Right + 3,
                form.BorderPadding.Left,
                rect.Width - iconRect.Right - textWidthDec - 6,
                rect.Height - form.BorderPadding.Left);

            using (AntiAliasGraphics antiGraphics = new AntiAliasGraphics(g))
            {
                DrawCaptionBackground(
                    g,
                    rect,
                    e.Active);

                if (form.ShowDrawIcon && form.Icon != null)
                {
                    DrawIcon(g, iconRect, form.Icon);
                }

                if (!string.IsNullOrEmpty(form.Text))
                {
                    Color EfColor    = form.EffectBack;
                    Color TitleColor = form.TitleColor;
                    //判断是否根据背景色适应颜色
                    if (form.TitleSuitColor)
                    {
                        //如果背景色为暗色
                        if (SkinTools.ColorSlantsDarkOrBright(form.BackColor))
                        {
                            TitleColor = Color.White;
                            EfColor    = Color.Black;
                        }
                        else//如果背景色为亮色
                        {
                            TitleColor = Color.Black;
                            EfColor    = Color.White;
                        }
                    }
                    DrawCaptionText(
                        g,
                        textRect,
                        form.Text,
                        form.CaptionFont,
                        form.EffectCaption,
                        EfColor,
                        form.EffectWidth,
                        TitleColor,
                        form.TitleOffset);
                }
            }
        }
示例#3
0
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            base.OnPaintBackground(e);
            //变量与初始化
            Graphics  g  = e.Graphics;
            Rectangle rc = this.ClientRectangle;

            g.SmoothingMode = SmoothingMode.AntiAlias;
            Color  baseColor;
            Color  CpBaseColor = BaseColor;
            Color  borderColor;
            Color  innerBorderColor = Color.FromArgb(200, 255, 255, 255);
            Bitmap btm = null;

            //停止当前状态
            if (StopState != StopStates.NoStop)
            {
                _controlState = (ControlState)StopState;
            }
            //获取父容器色调
            if (InheritColor)
            {
                CpBaseColor = this.Parent.BackColor;
            }
            //取得当前需要绘画的图像与色调
            switch (_controlState)
            {
            case ControlState.Hover:
                btm         = (Bitmap)MouseBack;
                baseColor   = GetColor(CpBaseColor, 0, -13, -8, -3);
                borderColor = CpBaseColor;
                break;

            case ControlState.Pressed:
                btm         = (Bitmap)DownBack;
                baseColor   = GetColor(CpBaseColor, 0, -35, -24, -9);
                borderColor = CpBaseColor;
                break;

            default:
                btm         = (Bitmap)NormlBack;
                baseColor   = CpBaseColor;
                borderColor = CpBaseColor;
                break;
            }
            if (!this.Enabled)
            {
                baseColor   = SystemColors.ControlDark;
                borderColor = SystemColors.ControlDark;
            }
            //如果有图则用图绘画
            if (btm != null && DrawType == DrawStyle.Img)
            {
                //绘制圆角
                SkinTools.CreateRegion(this, rc, Radius, RoundStyle);
                //绘制不规则区域
                if (Create && _controlState != states)
                {
                    SkinTools.CreateControlRegion(this, btm, 1);
                }
                //是否启用九宫绘图
                if (Palace)
                {
                    ImageDrawRect.DrawRect(g, btm, rc, Rectangle.FromLTRB(BackRectangle.X, BackRectangle.Y, BackRectangle.Width, BackRectangle.Height), 1, 1);
                }
                else
                {
                    g.DrawImage(btm, 0, 0, this.Width, this.Height);
                }
            }
            else if (DrawType == DrawStyle.Draw)  //无图则用色调绘图
            {
                RenderBackgroundInternal(
                    g,
                    rc,
                    baseColor,
                    borderColor,
                    innerBorderColor,
                    RoundStyle,
                    Radius,
                    0.35f,
                    true,
                    true,
                    LinearGradientMode.Vertical);
                //执行动画渐变效果
                if (FadeGlow)
                {
                    DrawButtonBackgroundFromBuffer(e.Graphics);
                }
            }

            #region 绘画文字和图像
            Image img = null;
            if (imageButton == null)
            {
                imageButton        = new Button();
                imageButton.Parent = new TransparentControl();
                imageButton.SuspendLayout();
                imageButton.BackColor = Color.Transparent;
                imageButton.FlatAppearance.BorderSize = 0;
                imageButton.FlatStyle = FlatStyle.Flat;
            }
            else
            {
                imageButton.SuspendLayout();
            }
            imageButton.AutoEllipsis = AutoEllipsis;
            if (Enabled)
            {
                Color txtColor = this.Enabled ? ForeColor : SystemColors.ControlDark;
                //是否根据背景色决定字体颜色
                if (ForeColorSuit)
                {
                    //如果背景色为暗色
                    if (SkinTools.ColorSlantsDarkOrBright(CpBaseColor))
                    {
                        txtColor = Color.White;
                    }
                    else//如果背景色为亮色
                    {
                        txtColor = Color.Black;
                    }
                }
                imageButton.ForeColor = txtColor;
            }
            else
            {
                imageButton.ForeColor = Color.FromArgb((3 * ForeColor.R + BaseColor.R) >> 2,
                                                       (3 * ForeColor.G + BaseColor.G) >> 2,
                                                       (3 * ForeColor.B + BaseColor.B) >> 2);
            }
            imageButton.Font        = Font;
            imageButton.RightToLeft = RightToLeft;
            if (imageButton.Image != Image && imageButton.Image != null)
            {
                imageButton.Image.Dispose();
            }
            if (Image != null)
            {
                img = this.Image;
                if (this.ImageList != null && this.ImageIndex != -1)
                {
                    img = this.ImageList.Images[this.ImageIndex];
                }
                Bitmap map = new Bitmap(img, ImageSize);
                imageButton.Image = map;
                if (!Enabled)
                {
                    using (Graphics gr = Graphics.FromImage(imageButton.Image))
                    {
                        ControlPaint.DrawImageDisabled(gr, Image, 0, 0, this.BaseColor);
                    }
                }
            }
            imageButton.ImageAlign                 = ImageAlign;
            imageButton.ImageIndex                 = ImageIndex;
            imageButton.ImageKey                   = ImageKey;
            imageButton.ImageList                  = ImageList;
            imageButton.Padding                    = Padding;
            imageButton.Size                       = Size;
            imageButton.Text                       = Text;
            imageButton.TextAlign                  = TextAlign;
            imageButton.TextImageRelation          = TextImageRelation;
            imageButton.UseCompatibleTextRendering = UseCompatibleTextRendering;
            imageButton.UseMnemonic                = UseMnemonic;
            imageButton.ResumeLayout();
            InvokePaint(imageButton, e);
            #endregion

            //储存上一个的样式状态
            states = _controlState;
        }
示例#4
0
        protected override void OnRenderSkinFormCaption(SkinFormCaptionRenderEventArgs e)
        {
            Graphics  graphics      = e.Graphics;
            Rectangle clipRectangle = e.ClipRectangle;
            FormBase  skinForm      = e.SkinForm;
            Rectangle iconRect      = skinForm.IconRect;
            Rectangle empty         = Rectangle.Empty;
            bool      controlBox    = skinForm.ControlBox;
            bool      flag2         = skinForm.ControlBox && skinForm.MinimizeBox;
            bool      flag3         = skinForm.ControlBox && skinForm.MaximizeBox;
            //bool flag4 = skinForm.ControlBox && skinForm.SysBottomVisibale;
            int num = 0;

            if (controlBox)
            {
                num += skinForm.CloseBoxSize.Width + skinForm.ControlBoxOffset.X;
            }
            if (flag3)
            {
                num += skinForm.MaxSize.Width + skinForm.ControlBoxSpace;
            }
            if (flag2)
            {
                num += skinForm.MiniSize.Width + skinForm.ControlBoxSpace;
            }
            foreach (CmSysButton button in (IEnumerable)skinForm.ControlBoxManager.SysButtonItems)
            {
                if (skinForm.ControlBox && button.Visibale)
                {
                    num += button.Size.Width + skinForm.ControlBoxSpace;
                }
            }
            empty = new Rectangle(iconRect.Right + 3, skinForm.BorderPadding.Left, ((clipRectangle.Width - iconRect.Right) - num) - 6, clipRectangle.Height - skinForm.BorderPadding.Left);
            using (new AntiAliasGraphics(graphics))
            {
                this.DrawCaptionBackground(graphics, clipRectangle, e.Active);
                if (skinForm.ShowIcon && (skinForm.Icon != null))
                {
                    this.DrawIcon(graphics, iconRect, skinForm.Icon);
                }
                if (!string.IsNullOrEmpty(skinForm.Text))
                {
                    Color effectBack = skinForm.EffectBack;
                    Color titleColor = skinForm.TitleColor;
                    if (skinForm.TitleSuitColor)
                    {
                        if (SkinTools.ColorSlantsDarkOrBright(skinForm.BackColor))
                        {
                            titleColor = Color.White;
                            effectBack = Color.Black;
                        }
                        else
                        {
                            titleColor = Color.Black;
                            effectBack = Color.White;
                        }
                    }
                    this.DrawCaptionText(graphics, empty, skinForm.Text, skinForm.CaptionFont, skinForm.EffectCaption, effectBack, skinForm.EffectWidth, titleColor, skinForm.TitleOffset);
                }
            }
        }
示例#5
0
        protected override void OnPaint(PaintEventArgs e)
        {
            Rectangle rectangle;
            Rectangle rectangle2;
            Color     controlDark;
            Color     color3;

            base.OnPaint(e);
            base.OnPaintBackground(e);
            Graphics  g = e.Graphics;
            Rectangle clientRectangle = base.ClientRectangle;

            this.CalculateRect(out rectangle, out rectangle2);
            g.SmoothingMode = SmoothingMode.AntiAlias;
            Color  baseColor        = this.BaseColor;
            Color  innerBorderColor = Color.FromArgb(200, 0xff, 0xff, 0xff);
            Bitmap mouseBack        = null;
            int    num = 0;

            if (this.StopState != StopStates.NoStop)
            {
                this._controlState = (ControlState)this.StopState;
            }
            if (this.InheritColor)
            {
                baseColor = base.Parent.BackColor;
            }
            switch (this._controlState)
            {
            case ControlState.Hover:
                mouseBack   = (Bitmap)this.MouseBack;
                controlDark = this.GetColor(baseColor, 0, -13, -8, -3);
                color3      = baseColor;
                break;

            case ControlState.Pressed:
                mouseBack   = (Bitmap)this.DownBack;
                controlDark = this.GetColor(baseColor, 0, -35, -24, -9);
                color3      = baseColor;
                num         = 1;
                break;

            default:
                mouseBack   = (Bitmap)this.NormlBack;
                controlDark = baseColor;
                color3      = baseColor;
                break;
            }
            if (!base.Enabled)
            {
                controlDark = SystemColors.ControlDark;
                color3      = SystemColors.ControlDark;
            }
            if ((mouseBack != null) && (this.DrawType == DrawStyle.Img))
            {
                SkinTools.CreateRegion(this, clientRectangle, this.Radius, this.RoundStyle);
                if (this.Create && (this._controlState != this.states))
                {
                    SkinTools.CreateControlRegion(this, mouseBack, 1);
                }
                if (this.Palace)
                {
                    ImageDrawRect.DrawRect(g, mouseBack, clientRectangle, Rectangle.FromLTRB(this.BackRectangle.X, this.BackRectangle.Y, this.BackRectangle.Width, this.BackRectangle.Height), 1, 1);
                }
                else
                {
                    g.DrawImage(mouseBack, 0, 0, base.Width, base.Height);
                }
            }
            else if (this.DrawType == DrawStyle.Draw)
            {
                this.RenderBackgroundInternal(g, clientRectangle, controlDark, color3, innerBorderColor, this.RoundStyle, this.Radius, 0.35f, true, true, LinearGradientMode.Vertical);
                if (this.FadeGlow)
                {
                    this.DrawButtonBackgroundFromBuffer(e.Graphics);
                }
            }
            Image image = null;
            Size  empty = Size.Empty;

            if (base.Image != null)
            {
                if (string.IsNullOrEmpty(this.Text))
                {
                    image = base.Image;
                    empty = new Size(image.Width, image.Height);
                    clientRectangle.Inflate(-4, -4);
                    if ((empty.Width * empty.Height) != 0)
                    {
                        Rectangle withinThis = clientRectangle;
                        withinThis = ImageDrawRect.HAlignWithin(empty, withinThis, base.ImageAlign);
                        withinThis = ImageDrawRect.VAlignWithin(empty, withinThis, base.ImageAlign);
                        if (!base.Enabled)
                        {
                            ControlPaint.DrawImageDisabled(g, image, withinThis.Left, withinThis.Top, this.BackColor);
                        }
                        else
                        {
                            g.DrawImage(image, withinThis.Left + num, withinThis.Top + num, image.Width, image.Height);
                        }
                    }
                }
                else
                {
                    g.InterpolationMode = InterpolationMode.HighQualityBilinear;
                    g.DrawImage(base.Image, rectangle, -num, -num, base.Image.Width, base.Image.Height, GraphicsUnit.Pixel);
                }
            }
            else if ((base.ImageList != null) && (base.ImageIndex != -1))
            {
                image = base.ImageList.Images[base.ImageIndex];
            }
            Color foreColor = base.Enabled ? this.ForeColor : SystemColors.ControlDark;

            if (this.ForeColorSuit)
            {
                if (SkinTools.ColorSlantsDarkOrBright(baseColor))
                {
                    foreColor = Color.White;
                }
                else
                {
                    foreColor = Color.Black;
                }
            }
            TextRenderer.DrawText(g, this.Text, this.Font, rectangle2, foreColor, GetTextFormatFlags(this.TextAlign, this.RightToLeft == RightToLeft.Yes));
            this.states = this._controlState;
        }