Exemplo n.º 1
0
        protected override void OnPaint(PaintEventArgs e)
        {
            UpdateColors();

            Bitmap   b = new Bitmap(Width, Height);
            Graphics g = Graphics.FromImage(b);

            _w = Width;
            _h = Height;

            GraphicsPath gp = new GraphicsPath();

            bool[] gcs = GetConnectedSides();
            // dynamic RoundedBase = Helpers.RoundRect(0, 0, W, H, ???, !(GCS(2) | GCS(1)), !(GCS(1) | GCS(0)), !(GCS(3) | GCS(0)), !(GCS(3) | GCS(2)));
            GraphicsPath roundedBase = Helpers.RoundRect(0, 0, _w, _h, 0.3, !(gcs[2] || gcs[1]), !(gcs[1] || gcs[0]), !(gcs[3] || gcs[0]), !(gcs[3] || gcs[2]));
            Rectangle    Base        = new Rectangle(0, 0, _w, _h);

            var with17 = g;

            with17.SmoothingMode     = SmoothingMode.HighQuality;
            with17.PixelOffsetMode   = PixelOffsetMode.HighQuality;
            with17.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
            with17.Clear(BackColor);

            switch (_state)
            {
            case MouseState.None:
                if (Rounded)
                {
                    //-- Base
                    gp = roundedBase;
                    with17.FillPath(new SolidBrush(_baseColor), gp);

                    //-- Text
                    with17.DrawString(Text, Font, new SolidBrush(_textColor), Base, Helpers.CenterSf);
                }
                else
                {
                    //-- Base
                    with17.FillRectangle(new SolidBrush(_baseColor), Base);

                    //-- Text
                    with17.DrawString(Text, Font, new SolidBrush(_textColor), Base, Helpers.CenterSf);
                }
                break;

            case MouseState.Over:
                if (Rounded)
                {
                    //-- Base
                    gp = roundedBase;
                    with17.FillPath(new SolidBrush(_baseColor), gp);
                    with17.FillPath(new SolidBrush(Color.FromArgb(20, Color.White)), gp);

                    //-- Text
                    with17.DrawString(Text, Font, new SolidBrush(_textColor), Base, Helpers.CenterSf);
                }
                else
                {
                    //-- Base
                    with17.FillRectangle(new SolidBrush(_baseColor), Base);
                    with17.FillRectangle(new SolidBrush(Color.FromArgb(20, Color.White)), Base);

                    //-- Text
                    with17.DrawString(Text, Font, new SolidBrush(_textColor), Base, Helpers.CenterSf);
                }
                break;

            case MouseState.Down:
                if (Rounded)
                {
                    //-- Base
                    gp = roundedBase;
                    with17.FillPath(new SolidBrush(_baseColor), gp);
                    with17.FillPath(new SolidBrush(Color.FromArgb(20, Color.Black)), gp);

                    //-- Text
                    with17.DrawString(Text, Font, new SolidBrush(_textColor), Base, Helpers.CenterSf);
                }
                else
                {
                    //-- Base
                    with17.FillRectangle(new SolidBrush(_baseColor), Base);
                    with17.FillRectangle(new SolidBrush(Color.FromArgb(20, Color.Black)), Base);

                    //-- Text
                    with17.DrawString(Text, Font, new SolidBrush(_textColor), Base, Helpers.CenterSf);
                }
                break;
            }

            base.OnPaint(e);
            g.Dispose();
            e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
            e.Graphics.DrawImageUnscaled(b, 0, 0);
            b.Dispose();
        }
Exemplo n.º 2
0
        protected override void OnPaint(PaintEventArgs e)
        {
            UpdateColors();

            Bitmap   B = new Bitmap(Width, Height);
            Graphics G = Graphics.FromImage(B);

            W = Width;
            H = Height;

            GraphicsPath GP = new GraphicsPath();

            bool[] GCS = GetConnectedSides();
            // dynamic RoundedBase = Helpers.RoundRect(0, 0, W, H, ???, !(GCS(2) | GCS(1)), !(GCS(1) | GCS(0)), !(GCS(3) | GCS(0)), !(GCS(3) | GCS(2)));
            GraphicsPath RoundedBase = Helpers.RoundRect(0, 0, W, H, 0.3, !(GCS[2] || GCS[1]), !(GCS[1] || GCS[0]), !(GCS[3] || GCS[0]), !(GCS[3] || GCS[2]));
            Rectangle    Base        = new Rectangle(0, 0, W, H);

            var _with17 = G;

            _with17.SmoothingMode     = SmoothingMode.HighQuality;
            _with17.PixelOffsetMode   = PixelOffsetMode.HighQuality;
            _with17.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
            _with17.Clear(BackColor);

            switch (State)
            {
            case MouseState.None:
                if (Rounded)
                {
                    //-- Base
                    GP = RoundedBase;
                    _with17.FillPath(new SolidBrush(_BaseColor), GP);

                    //-- Text
                    _with17.DrawString(Text, Font, new SolidBrush(_TextColor), Base, Helpers.CenterSF);
                }
                else
                {
                    //-- Base
                    _with17.FillRectangle(new SolidBrush(_BaseColor), Base);

                    //-- Text
                    _with17.DrawString(Text, Font, new SolidBrush(_TextColor), Base, Helpers.CenterSF);
                }
                break;

            case MouseState.Over:
                if (Rounded)
                {
                    //-- Base
                    GP = RoundedBase;
                    _with17.FillPath(new SolidBrush(_BaseColor), GP);
                    _with17.FillPath(new SolidBrush(Color.FromArgb(20, Color.White)), GP);

                    //-- Text
                    _with17.DrawString(Text, Font, new SolidBrush(_TextColor), Base, Helpers.CenterSF);
                }
                else
                {
                    //-- Base
                    _with17.FillRectangle(new SolidBrush(_BaseColor), Base);
                    _with17.FillRectangle(new SolidBrush(Color.FromArgb(20, Color.White)), Base);

                    //-- Text
                    _with17.DrawString(Text, Font, new SolidBrush(_TextColor), Base, Helpers.CenterSF);
                }
                break;

            case MouseState.Down:
                if (Rounded)
                {
                    //-- Base
                    GP = RoundedBase;
                    _with17.FillPath(new SolidBrush(_BaseColor), GP);
                    _with17.FillPath(new SolidBrush(Color.FromArgb(20, Color.Black)), GP);

                    //-- Text
                    _with17.DrawString(Text, Font, new SolidBrush(_TextColor), Base, Helpers.CenterSF);
                }
                else
                {
                    //-- Base
                    _with17.FillRectangle(new SolidBrush(_BaseColor), Base);
                    _with17.FillRectangle(new SolidBrush(Color.FromArgb(20, Color.Black)), Base);

                    //-- Text
                    _with17.DrawString(Text, Font, new SolidBrush(_TextColor), Base, Helpers.CenterSF);
                }
                break;
            }

            base.OnPaint(e);
            G.Dispose();
            e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
            e.Graphics.DrawImageUnscaled(B, 0, 0);
            B.Dispose();
        }
Exemplo n.º 3
0
        protected override void OnPaint(PaintEventArgs e)
        {
            this.UpdateColors();
            Bitmap   bitmap    = new Bitmap(this.Width, this.Height);
            Graphics graphics1 = Graphics.FromImage((Image)bitmap);

            this.W = this.Width;
            this.H = this.Height;
            GraphicsPath graphicsPath1 = new GraphicsPath();

            bool[]       connectedSides = this.GetConnectedSides();
            GraphicsPath graphicsPath2  = Helpers.RoundRect(0.0f, 0.0f, (float)this.W, (float)this.H, 0.3, !connectedSides[2] && !connectedSides[1], !connectedSides[1] && !connectedSides[0], !connectedSides[3] && !connectedSides[0], !connectedSides[3] && !connectedSides[2]);
            Rectangle    rect           = new Rectangle(0, 0, this.W, this.H);
            Graphics     graphics2      = graphics1;

            graphics2.SmoothingMode     = SmoothingMode.HighQuality;
            graphics2.PixelOffsetMode   = PixelOffsetMode.HighQuality;
            graphics2.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
            graphics2.Clear(this.BackColor);
            switch (this.State)
            {
            case MouseState.None:
                if (this.Rounded)
                {
                    GraphicsPath path = graphicsPath2;
                    graphics2.FillPath((Brush) new SolidBrush(this._BaseColor), path);
                    graphics2.DrawString(this.Text, this.Font, (Brush) new SolidBrush(this._TextColor), (RectangleF)rect, Helpers.CenterSF);
                    break;
                }
                graphics2.FillRectangle((Brush) new SolidBrush(this._BaseColor), rect);
                graphics2.DrawString(this.Text, this.Font, (Brush) new SolidBrush(this._TextColor), (RectangleF)rect, Helpers.CenterSF);
                break;

            case MouseState.Over:
                if (this.Rounded)
                {
                    GraphicsPath path = graphicsPath2;
                    graphics2.FillPath((Brush) new SolidBrush(this._BaseColor), path);
                    graphics2.FillPath((Brush) new SolidBrush(Color.FromArgb(20, Color.White)), path);
                    graphics2.DrawString(this.Text, this.Font, (Brush) new SolidBrush(this._TextColor), (RectangleF)rect, Helpers.CenterSF);
                    break;
                }
                graphics2.FillRectangle((Brush) new SolidBrush(this._BaseColor), rect);
                graphics2.FillRectangle((Brush) new SolidBrush(Color.FromArgb(20, Color.White)), rect);
                graphics2.DrawString(this.Text, this.Font, (Brush) new SolidBrush(this._TextColor), (RectangleF)rect, Helpers.CenterSF);
                break;

            case MouseState.Down:
                if (this.Rounded)
                {
                    GraphicsPath path = graphicsPath2;
                    graphics2.FillPath((Brush) new SolidBrush(this._BaseColor), path);
                    graphics2.FillPath((Brush) new SolidBrush(Color.FromArgb(20, Color.Black)), path);
                    graphics2.DrawString(this.Text, this.Font, (Brush) new SolidBrush(this._TextColor), (RectangleF)rect, Helpers.CenterSF);
                    break;
                }
                graphics2.FillRectangle((Brush) new SolidBrush(this._BaseColor), rect);
                graphics2.FillRectangle((Brush) new SolidBrush(Color.FromArgb(20, Color.Black)), rect);
                graphics2.DrawString(this.Text, this.Font, (Brush) new SolidBrush(this._TextColor), (RectangleF)rect, Helpers.CenterSF);
                break;
            }
            base.OnPaint(e);
            graphics1.Dispose();
            e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
            e.Graphics.DrawImageUnscaled((Image)bitmap, 0, 0);
            bitmap.Dispose();
        }