Exemple #1
0
 //大小改变时
 protected override void OnSizeChanged(EventArgs e)
 {
     if (SkinBack != null && show)
     {
         SkinTools.CreateControlRegion(this, TrankBack(), 255);
         skin.Size = this.Size;
     }
     base.OnSizeChanged(e);
 }
Exemple #2
0
 protected override void OnVisibleChanged(EventArgs e)
 {
     if (!DesignMode)
     {
         if (skin != null)
         {
             skin.Visible = this.Visible;
         }
         else
         {
             SkinTools.CreateControlRegion(this, TrankBack(), 255);
             show = true;
             skin = new SkinForm(this);
             skin.Show();
         }
     }
     base.OnVisibleChanged(e);
 }
        private void DrawProgressBar(IntPtr hWnd)
        {
            bool     flag;
            Graphics graphics = this._bufferedGraphics.Graphics;

            graphics.Clear(Color.Transparent);
            Rectangle             rect         = new Rectangle(System.Drawing.Point.Empty, base.Size);
            float                 basePosition = (flag = (this.Style != ProgressBarStyle.Marquee) || base.DesignMode) ? 0.3f : 0.45f;
            SmoothingModeGraphics graphics2    = new SmoothingModeGraphics(graphics);

            if (this.Back != null)
            {
                Bitmap bitmap = new Bitmap(this.Back, base.Size);
                SkinTools.CreateControlRegion(this, bitmap, 200);
                graphics.DrawImage(this.Back, rect);
            }
            else
            {
                RenderHelper.RenderBackgroundInternal(graphics, rect, this.TrackBack, this.Border, this.InnerBorder, this.RadiusStyle, this.Radius, basePosition, true, this.Glass, LinearGradientMode.Vertical);
            }
            Rectangle rectangle2 = rect;

            rectangle2.Inflate(-this.BarMinusSize.Width, -this.BarMinusSize.Height);
            if (!flag)
            {
                GraphicsState gstate = graphics.Save();
                graphics.SetClip(rectangle2);
                rectangle2.X     = this._trackX;
                rectangle2.Width = 100;
                using (GraphicsPath path = new GraphicsPath())
                {
                    path.AddEllipse(rectangle2);
                    graphics.SetClip(path, CombineMode.Intersect);
                }
                RenderHelper.RenderBackgroundInternal(graphics, rectangle2, this.TrackFore, this.Border, this.InnerBorder, RoundStyle.None, 8, basePosition, false, this.BarGlass, LinearGradientMode.Vertical);
                using (LinearGradientBrush brush2 = new LinearGradientBrush(rectangle2, this.InnerBorder, Color.Transparent, 0f))
                {
                    Blend   blend    = new Blend();
                    float[] numArray = new float[3];
                    numArray[1]   = 1f;
                    blend.Factors = numArray;
                    float[] numArray2 = new float[3];
                    numArray2[1]    = 0.5f;
                    numArray2[2]    = 1f;
                    blend.Positions = numArray2;
                    brush2.Blend    = blend;
                    graphics.FillRectangle(brush2, rectangle2);
                }
                graphics.Restore(gstate);
                goto Label_02F1;
            }
            rectangle2.Width = (int)((((double)base.Value) / ((double)(base.Maximum - base.Minimum))) * rectangle2.Width);
            if (this.BarBack != null)
            {
                if (this.BarBackStyle == BackStyle.Tile)
                {
                    using (TextureBrush brush = new TextureBrush(this.BarBack))
                    {
                        brush.WrapMode = WrapMode.Tile;
                        graphics.FillRectangle(brush, rectangle2);
                        goto Label_019B;
                    }
                }
                Bitmap image = new Bitmap(this.BarBack, base.Size);
                graphics.DrawImageUnscaledAndClipped(image, rectangle2);
            }
            else
            {
                RenderHelper.RenderBackgroundInternal(graphics, rectangle2, this.TrackFore, this.Border, this.InnerBorder, this.BarRadiusStyle, this.BarRadius, basePosition, false, this.BarGlass, LinearGradientMode.Vertical);
            }
Label_019B:
            if (!string.IsNullOrEmpty(this._formatString) && this.TxtShow)
            {
                TextRenderer.DrawText(graphics, string.Format(this._formatString, ((double)base.Value) / ((double)(base.Maximum - base.Minimum))), base.Font, rect, base.ForeColor, TextFormatFlags.WordEllipsis | TextFormatFlags.SingleLine | TextFormatFlags.VerticalCenter | TextFormatFlags.HorizontalCenter);
            }
Label_02F1:
            graphics2.Dispose();
            IntPtr dC = NativeMethods.GetDC(hWnd);

            this._bufferedGraphics.Render(dC);
            NativeMethods.ReleaseDC(hWnd, dC);
        }
Exemple #4
0
        private void DrawProgressBar(IntPtr hWnd)
        {
            Graphics g = _bufferedGraphics.Graphics;

            g.Clear(Color.Transparent);
            Rectangle rect = new Rectangle(Point.Empty, Size);

            bool  bBlock       = Style != ProgressBarStyle.Marquee || base.DesignMode;
            float basePosition = bBlock ? .30f : .45f;

            SmoothingModeGraphics sg = new SmoothingModeGraphics(g);

            if (Back != null)
            {
                Bitmap btm = new Bitmap(Back, this.Size);
                if (Create)
                {
                    SkinTools.CreateControlRegion(this, btm, 200);
                }
                g.DrawImage(Back, rect);
            }
            else
            {
                RenderHelper.RenderBackgroundInternal(
                    g,
                    rect,
                    TrackBack,
                    Border,
                    InnerBorder,
                    RadiusStyle,
                    Radius,
                    basePosition,
                    true,
                    Glass,
                    LinearGradientMode.Vertical);
            }
            Rectangle trackRect = rect;

            trackRect.Inflate(-BarMinusSize.Width, -BarMinusSize.Height);
            if (bBlock)
            {
                trackRect.Width = (int)(((double)Value / (Maximum - Minimum)) * trackRect.Width);
                if (BarBack != null)
                {
                    if (BarBackStyle == BackStyle.Tile)
                    {
                        using (TextureBrush Txbrus = new TextureBrush(BarBack))
                        {
                            Txbrus.WrapMode = System.Drawing.Drawing2D.WrapMode.Tile;
                            g.FillRectangle(Txbrus, trackRect);
                        }
                    }
                    else
                    {
                        Bitmap btm = new Bitmap(BarBack, this.Size);
                        g.DrawImageUnscaledAndClipped(btm, trackRect);
                    }
                }
                else
                {
                    RenderHelper.RenderBackgroundInternal(
                        g,
                        trackRect,
                        TrackFore,
                        Border,
                        InnerBorder,
                        BarRadiusStyle,
                        BarRadius,
                        basePosition,
                        false,
                        BarGlass,
                        LinearGradientMode.Vertical);
                }
                if (!string.IsNullOrEmpty(_formatString) && TextFormat == TxtFormat.Percentage)
                {
                    TextRenderer.DrawText(
                        g,
                        string.Format(_formatString, (double)Value / (Maximum - Minimum)),
                        base.Font,
                        rect,
                        base.ForeColor,
                        TextFormatFlags.VerticalCenter |
                        TextFormatFlags.HorizontalCenter |
                        TextFormatFlags.SingleLine |
                        TextFormatFlags.WordEllipsis);
                }
                else if (TextFormat == TxtFormat.Proportion)
                {
                    TextRenderer.DrawText(
                        g,
                        Value + "/" + Maximum,
                        base.Font,
                        rect,
                        base.ForeColor,
                        TextFormatFlags.VerticalCenter |
                        TextFormatFlags.HorizontalCenter |
                        TextFormatFlags.SingleLine |
                        TextFormatFlags.WordEllipsis);
                }
            }
            else
            {
                GraphicsState state = g.Save();

                g.SetClip(trackRect);

                trackRect.X     = _trackX;
                trackRect.Width = MarqueeWidth;

                using (GraphicsPath path = new GraphicsPath())
                {
                    path.AddEllipse(trackRect);
                    g.SetClip(path, CombineMode.Intersect);
                }

                RenderHelper.RenderBackgroundInternal(
                    g,
                    trackRect,
                    TrackFore,
                    Border,
                    InnerBorder,
                    RoundStyle.None,
                    8,
                    basePosition,
                    false,
                    BarGlass,
                    LinearGradientMode.Vertical);

                using (LinearGradientBrush brush = new LinearGradientBrush(
                           trackRect, InnerBorder, Color.Transparent, 0f))
                {
                    Blend blend = new Blend();
                    blend.Factors   = new float[] { 0f, 1f, 0f };
                    blend.Positions = new float[] { 0f, .5f, 1f };
                    brush.Blend     = blend;

                    g.FillRectangle(brush, trackRect);
                }

                g.Restore(state);
            }

            sg.Dispose();

            IntPtr hDC = NativeMethods.GetDC(hWnd);

            _bufferedGraphics.Render(hDC);
            NativeMethods.ReleaseDC(hWnd, hDC);
        }
Exemple #5
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;
        }
Exemple #6
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;
        }