Ejemplo n.º 1
0
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            LinearGradientBrush LGB = default(LinearGradientBrush);
            GraphicsPath        GP  = default(GraphicsPath);

            e.Graphics.Clear(BackColor);
            e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;

            // Create a curvy border
            GP = RoundRectangle.RoundRect(0, 0, Width - 1, Height - 1, 5);
            // Fills the body of the rectangle with a gradient
            LGB = new LinearGradientBrush(ClientRectangle, Color.FromArgb(241, 241, 241), Color.FromArgb(241, 241, 241), 90f);

            e.Graphics.SetClip(GP);
            e.Graphics.FillRectangle(LGB, ClientRectangle);
            e.Graphics.ResetClip();

            // Draw rectangle border
            e.Graphics.DrawPath(new Pen(Color.FromArgb(204, 204, 204)), GP);
            // Draw string
            e.Graphics.DrawString(Text, Font, new SolidBrush(ForeColor), new Rectangle(3, 0, Width - 20, Height), new StringFormat
            {
                LineAlignment = StringAlignment.Center,
                Alignment     = StringAlignment.Near
            });

            // Draw the dropdown arrow
            e.Graphics.DrawLine(new Pen(Color.FromArgb(160, 160, 160), 2), new Point(Width - 18, 10), new Point(Width - 14, 14));
            e.Graphics.DrawLine(new Pen(Color.FromArgb(160, 160, 160), 2), new Point(Width - 14, 14), new Point(Width - 10, 10));
            e.Graphics.DrawLine(new Pen(Color.FromArgb(160, 160, 160)), new Point(Width - 14, 15), new Point(Width - 14, 14));

            GP.Dispose();
            LGB.Dispose();
        }
Ejemplo n.º 2
0
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            Bitmap    B        = new Bitmap(Width, Height);
            Graphics  G        = Graphics.FromImage(B);
            Rectangle TitleBox = new Rectangle(51, 3, Width - 103, 18);
            Rectangle box      = new Rectangle(0, 0, Width - 1, Height - 10);

            G.Clear(Color.Transparent);
            G.SmoothingMode = SmoothingMode.HighQuality;

            // Draw the body of the GroupBox
            G.FillPath(new SolidBrush(_BackGColor), RoundRectangle.RoundRect(new Rectangle(1, 12, Width - 3, box.Height - 1), 8));
            // Draw the border of the GroupBox
            G.DrawPath(new Pen(_BorderColorG), RoundRectangle.RoundRect(new Rectangle(1, 12, Width - 3, Height - 13), 8));

            // Draw the background of the title box
            G.FillPath(new SolidBrush(_HeaderColor), RoundRectangle.RoundRect(TitleBox, 1));
            // Draw the border of the title box
            G.DrawPath(new Pen(_BorderColorH), RoundRectangle.RoundRect(TitleBox, 4));
            // Draw the specified string from 'Text' property inside the title box
            G.DrawString(Text, Font, new SolidBrush(ForeColor), TitleBox, new StringFormat
            {
                Alignment     = StringAlignment.Center,
                LineAlignment = StringAlignment.Center
            });

            e.Graphics.DrawImage((Image)B.Clone(), 0, 0);
            G.Dispose();
            B.Dispose();
        }
Ejemplo n.º 3
0
        protected override void OnPaint(PaintEventArgs e)
        {
            Graphics  G = e.Graphics;
            Rectangle ItemBoundsRect = new Rectangle();

            G.Clear(_BaseColor);
            for (int TabIndex = 0; TabIndex <= TabCount - 1; TabIndex++)
            {
                ItemBoundsRect = GetTabRect(TabIndex);
                if (!(TabIndex == SelectedIndex))
                {
                    G.DrawString(TabPages[TabIndex].Text, new Font(Font.Name, Font.Size - 2, FontStyle.Bold), new SolidBrush(_DeactivePageTextColor), new Rectangle(GetTabRect(TabIndex).Location, GetTabRect(TabIndex).Size), new StringFormat
                    {
                        LineAlignment = StringAlignment.Center,
                        Alignment     = StringAlignment.Center
                    });
                }
            }

            // Draw container rectangle
            G.FillPath(new SolidBrush(_PageEdgeColor), RoundRectangle.RoundRect(0, 23, Width - 1, Height - 24, 2));
            G.DrawPath(new Pen(_PageEdgeBorderColor), RoundRectangle.RoundRect(0, 23, Width - 1, Height - 24, 2));

            for (int ItemIndex = 0; ItemIndex <= TabCount - 1; ItemIndex++)
            {
                ItemBoundsRect = GetTabRect(ItemIndex);
                if (ItemIndex == SelectedIndex)
                {
                    // Draw header tabs
                    G.DrawPath(new Pen(_ActivePageBorderColor), RoundRectangle.RoundedTopRect(new Rectangle(new Point(ItemBoundsRect.X - 2, ItemBoundsRect.Y - 2), new Size(ItemBoundsRect.Width + 3, ItemBoundsRect.Height)), 7));
                    G.FillPath(new SolidBrush(_ActivePageBackColor), RoundRectangle.RoundedTopRect(new Rectangle(new Point(ItemBoundsRect.X - 1, ItemBoundsRect.Y - 1), new Size(ItemBoundsRect.Width + 2, ItemBoundsRect.Height)), 7));

                    try
                    {
                        G.DrawString(TabPages[ItemIndex].Text, new Font(Font.Name, Font.Size - 1, FontStyle.Bold), new SolidBrush(_ActivePageTextColor), new Rectangle(GetTabRect(ItemIndex).Location, GetTabRect(ItemIndex).Size), new StringFormat
                        {
                            LineAlignment = StringAlignment.Center,
                            Alignment     = StringAlignment.Center
                        });
                        TabPages[ItemIndex].BackColor = _PageBackColor;
                    }
                    catch
                    {
                    }
                }
            }
        }
Ejemplo n.º 4
0
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            Bitmap    B = new Bitmap(Width, Height);
            Graphics  G = Graphics.FromImage(B);
            Rectangle ClientRectangle = new Rectangle(0, 0, Width - 1, Height - 1);
            Color     TransparencyKey = ParentForm.TransparencyKey;

            G.SmoothingMode = SmoothingMode.Default;
            G.Clear(TransparencyKey);

            // Draw the container borders
            G.FillPath(new SolidBrush(Color.FromArgb(52, 52, 52)), RoundRectangle.RoundRect(ClientRectangle, BorderCurve));
            // Draw a rectangle in which the controls should be added on
            G.FillPath(new SolidBrush(Color.FromArgb(32, 41, 50)), RoundRectangle.RoundRect(new Rectangle(2, 20, Width - 5, Height - 42), BorderCurve));

            // Patch the header with a rectangle that has a curve so its border will remain within container bounds
            G.FillPath(new SolidBrush(Color.FromArgb(52, 52, 52)), RoundRectangle.RoundRect(new Rectangle(2, 2, (int)(Width / 2 + 2), 16), BorderCurve));
            G.FillPath(new SolidBrush(Color.FromArgb(52, 52, 52)), RoundRectangle.RoundRect(new Rectangle((int)(Width / 2 - 3), 2, (int)(Width / 2), 16), BorderCurve));
            // Fill the header rectangle below the patch
            G.FillRectangle(new SolidBrush(Color.FromArgb(52, 52, 52)), new Rectangle(2, 15, Width - 5, 10));

            // Increase the thickness of the container borders
            G.DrawPath(new Pen(Color.FromArgb(52, 52, 52)), RoundRectangle.RoundRect(new Rectangle(2, 2, Width - 5, Height - 5), BorderCurve));
            G.DrawPath(new Pen(Color.FromArgb(52, 52, 52)), RoundRectangle.RoundRect(ClientRectangle, BorderCurve));

            // Draw the string from the specified 'Text' property on the header rectangle
            G.DrawString(Text, new Font("Trebuchet MS", 10, FontStyle.Bold), new SolidBrush(Color.FromArgb(221, 221, 221)), new Rectangle(BorderCurve, BorderCurve - 4, Width - 1, 22), new StringFormat()
            {
                Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Near
            });

            // Draws a rectangle at the bottom of the container
            G.FillRectangle(new SolidBrush(Color.FromArgb(52, 52, 52)), 0, Height - 25, Width - 3, 22 - 2);
            G.DrawLine(new Pen(Color.FromArgb(52, 52, 52)), 5, Height - 5, Width - 6, Height - 5);
            G.DrawLine(new Pen(Color.FromArgb(52, 52, 52)), 7, Height - 4, Width - 7, Height - 4);

            G.DrawString(_TextBottom, new Font("Trebuchet MS", 10, FontStyle.Bold), new SolidBrush(Color.FromArgb(221, 221, 221)), 5, Height - 23);

            e.Graphics.DrawImage((Image)(B.Clone()), 0, 0);
            G.Dispose();
            B.Dispose();
        }
Ejemplo n.º 5
0
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            Graphics   G     = e.Graphics;
            HatchBrush Hatch = new HatchBrush(HatchStyle.WideDownwardDiagonal, Color.FromArgb(20, Color.Black), Color.Transparent);

            G.Clear(Parent.BackColor);
            G.SmoothingMode = SmoothingMode.AntiAlias;
            checked
            {
                PipeBorder = RoundRectangle.RoundRect(1, 6, Width - 3, 8, 3);
                try
                {
                    ValueDrawer = (int)Math.Round(unchecked (checked ((double)(_Value - _Minimum) / (double)(_Maximum - _Minimum)) * (double)checked (Width - 11)));
                }
                catch (Exception)
                {
                }
                TrackBarHandleRect = new Rectangle(ValueDrawer, 0, 10, 20);
                G.SetClip(PipeBorder);
                ValueRect = new Rectangle(1, 7, TrackBarHandleRect.X + TrackBarHandleRect.Width - 2, 7);
                VlaueLGB  = new LinearGradientBrush(ValueRect, _ValueColour, _ValueColour, 90f);
                G.FillRectangle(VlaueLGB, ValueRect);

                if (_DrawHatch == true)
                {
                    G.FillRectangle(Hatch, ValueRect);
                }

                G.ResetClip();
                G.SmoothingMode = SmoothingMode.AntiAlias;
                G.DrawPath(new Pen(Color.FromArgb(180, 180, 180)), PipeBorder);
                TrackBarHandle    = RoundRectangle.RoundRect(TrackBarHandleRect, 3);
                TrackBarHandleLGB = new LinearGradientBrush(ClientRectangle, SystemColors.Control, SystemColors.Control, 90f);
                G.FillPath(TrackBarHandleLGB, TrackBarHandle);
                G.DrawPath(new Pen(Color.FromArgb(180, 180, 180)), TrackBarHandle);

                if (_DrawValueString == true)
                {
                    G.DrawString(Convert.ToString(ValueToSet), Font, Brushes.Gray, 0, 25);
                }
            }
        }
Ejemplo n.º 6
0
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            Graphics G = e.Graphics;

            G.Clear(Parent.BackColor);
            G.SmoothingMode = SmoothingMode.AntiAlias;
            TrackThumb      = new Rectangle(8, 10, Width - 16, 2);
            PipeBorder      = RoundRectangle.RoundRect(1, 8, Width - 3, 5, 2);

            try
            {
                ValueDrawer = (int)Math.Round(((double)(_Value - _Minimum) / (double)(_Maximum - _Minimum)) * (double)(Width - 11));
            }
            catch (Exception)
            {
            }

            TrackBarHandleRect = new Rectangle(ValueDrawer, 0, 10, 20);

            G.SetClip(PipeBorder); // Set the clipping region of this Graphics to the specified GraphicsPath
            G.FillPath(new SolidBrush(_EmptyBackColor), PipeBorder);
            FillValue = RoundRectangle.RoundRect(1, 8, TrackBarHandleRect.X + TrackBarHandleRect.Width - 4, 5, 2);

            G.ResetClip(); // Reset the clip region of this Graphics to an infinite region

            G.SmoothingMode = SmoothingMode.HighQuality;
            G.DrawPath(new Pen(_BorderColor), PipeBorder); // Draw pipe border
            G.FillPath(new SolidBrush(_FillBackColor), FillValue);

            G.FillEllipse(new SolidBrush(_ThumbBackColor), TrackThumb.X + (int)Math.Round(unchecked ((double)TrackThumb.Width * ((double)Value / (double)Maximum))) - (int)Math.Round((double)ThumbSize.Width / 2.0), TrackThumb.Y + (int)Math.Round((double)TrackThumb.Height / 2.0) - (int)Math.Round((double)ThumbSize.Height / 2.0), ThumbSize.Width, ThumbSize.Height);
            G.DrawEllipse(new Pen(_ThumbBorderColor), TrackThumb.X + (int)Math.Round(unchecked ((double)TrackThumb.Width * ((double)Value / (double)Maximum))) - (int)Math.Round((double)ThumbSize.Width / 2.0), TrackThumb.Y + (int)Math.Round((double)TrackThumb.Height / 2.0) - (int)Math.Round((double)ThumbSize.Height / 2.0), ThumbSize.Width, ThumbSize.Height);

            if (_DrawValueString == true)
            {
                G.DrawString(Convert.ToString(ValueToSet), Font, Brushes.DimGray, 1, 20);
            }
        }
Ejemplo n.º 7
0
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            LinearGradientBrush LGB = default(LinearGradientBrush);
            GraphicsPath        GP  = default(GraphicsPath);

            e.Graphics.Clear(Parent.BackColor);
            e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;

            // Create a curvy border
            GP = RoundRectangle.RoundRect(0, 0, Width - 1, Height - 1, 5);
            // Fills the body of the rectangle with a gradient
            LGB = new LinearGradientBrush(ClientRectangle, _ColorD, _ColorE, 90.0F);

            e.Graphics.SetClip(GP);
            e.Graphics.FillRectangle(LGB, ClientRectangle);
            e.Graphics.ResetClip();

            // Draw rectangle border
            e.Graphics.DrawPath(new Pen(_ColorF), GP);
            // Draw string
            e.Graphics.DrawString(Text, Font, new SolidBrush(ForeColor), new Rectangle(3, 0, Width - 20, Height), new StringFormat
            {
                LineAlignment = StringAlignment.Center,
                Alignment     = StringAlignment.Near
            });
            e.Graphics.DrawString("6", new Font("Marlett", 13, FontStyle.Regular), new SolidBrush(_ColorG), new Rectangle(3, 0, Width - 4, Height), new StringFormat
            {
                LineAlignment = StringAlignment.Center,
                Alignment     = StringAlignment.Far
            });
            e.Graphics.DrawLine(new Pen(_ColorH), Width - 24, 4, Width - 24, Height - 5);
            e.Graphics.DrawLine(new Pen(_ColorI), Width - 25, 4, Width - 25, Height - 5);

            GP.Dispose();
            LGB.Dispose();
        }
Ejemplo n.º 8
0
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

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

            GP_MinimizeRect.AddRectangle(MinimizeRect);
            GP_CloseRect.AddRectangle(CloseRect);
            G.Clear(BackColor);

            switch (State)
            {
            case MouseState.None:
NonePoint:
                LinearGradientBrush MinimizeGradient = new LinearGradientBrush(MinimizeRect, Color.FromArgb(73, 73, 73), Color.FromArgb(58, 58, 58), 90);
                G.FillPath(MinimizeGradient, GP_MinimizeRect);
                G.DrawPath(new Pen(Color.FromArgb(40, 40, 40)), GP_MinimizeRect);
                G.DrawString("0", new Font("Marlett", 11, FontStyle.Regular), new SolidBrush(Color.FromArgb(221, 221, 221)), MinimizeRect.Width - 22, MinimizeRect.Height - 16);

                LinearGradientBrush CloseGradient = new LinearGradientBrush(CloseRect, Color.FromArgb(73, 73, 73), Color.FromArgb(58, 58, 58), 90);
                G.FillPath(CloseGradient, GP_CloseRect);
                G.DrawPath(new Pen(Color.FromArgb(40, 40, 40)), GP_CloseRect);
                G.DrawString("r", new Font("Marlett", 11, FontStyle.Regular), new SolidBrush(Color.FromArgb(221, 221, 221)), CloseRect.Width - 4, CloseRect.Height - 16);
                break;

            case MouseState.Over:
                if (i > 0 & i < 28)
                {
                    LinearGradientBrush xMinimizeGradient = new LinearGradientBrush(MinimizeRect, Color.FromArgb(76, 76, 76, 76), Color.FromArgb(48, 48, 48), 90f);
                    G.FillPath(xMinimizeGradient, GP_MinimizeRect);
                    G.DrawPath(new Pen(Color.FromArgb(40, 40, 40)), GP_MinimizeRect);
                    G.DrawString("0", new Font("Marlett", 11, FontStyle.Regular), new SolidBrush(Color.FromArgb(221, 221, 221)), MinimizeRect.Width - 22, MinimizeRect.Height - 16);

                    LinearGradientBrush xCloseGradient = new LinearGradientBrush(CloseRect, Color.FromArgb(73, 73, 73), Color.FromArgb(58, 58, 58), 90);
                    G.FillPath(xCloseGradient, GP_CloseRect);
                    G.DrawPath(new Pen(Color.FromArgb(40, 40, 40)), GP_CloseRect);
                    G.DrawString("r", new Font("Marlett", 11, FontStyle.Regular), new SolidBrush(Color.FromArgb(221, 221, 221)), CloseRect.Width - 4, CloseRect.Height - 16);
                }
                else if (i > 30 & i < 75)
                {
                    LinearGradientBrush xCloseGradient = new LinearGradientBrush(CloseRect, Color.FromArgb(76, 76, 76, 76), Color.FromArgb(48, 48, 48), 90);
                    G.FillPath(xCloseGradient, GP_CloseRect);
                    G.DrawPath(new Pen(Color.FromArgb(40, 40, 40)), GP_CloseRect);
                    G.DrawString("r", new Font("Marlett", 11, FontStyle.Regular), new SolidBrush(Color.FromArgb(221, 221, 221)), CloseRect.Width - 4, CloseRect.Height - 16);

                    LinearGradientBrush xMinimizeGradient = new LinearGradientBrush(MinimizeRect, Color.FromArgb(73, 73, 73), Color.FromArgb(58, 58, 58), 90);
                    G.FillPath(xMinimizeGradient, RoundRectangle.RoundRect(MinimizeRect, 1));
                    G.DrawPath(new Pen(Color.FromArgb(40, 40, 40)), GP_MinimizeRect);
                    G.DrawString("0", new Font("Marlett", 11, FontStyle.Regular), new SolidBrush(Color.FromArgb(221, 221, 221)), MinimizeRect.Width - 22, MinimizeRect.Height - 16);
                }
                else
                {
                    goto NonePoint;     // Return to [MouseState = None]
                }
                break;
            }

            e.Graphics.DrawImage((Image)B.Clone(), 0, 0);
            G.Dispose();
            GP_CloseRect.Dispose();
            GP_MinimizeRect.Dispose();
            B.Dispose();
        }
Ejemplo n.º 9
0
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            Graphics G = e.Graphics;

            G.SmoothingMode = SmoothingMode.HighQuality;
            G.Clear(Parent.BackColor);

            int          SwitchXLoc       = 3;
            Rectangle    ControlRectangle = new Rectangle(0, 0, Width - 1, Height - 1);
            GraphicsPath ControlPath      = RoundRectangle.RoundRect(ControlRectangle, 4);

            LinearGradientBrush BackgroundLGB = default(LinearGradientBrush);

            if (_Toggled)
            {
                SwitchXLoc    = 37;
                BackgroundLGB = new LinearGradientBrush(ControlRectangle, _ToggledColorA, _ToggledColorB, 90.0F);
            }
            else
            {
                SwitchXLoc    = 0;
                BackgroundLGB = new LinearGradientBrush(ControlRectangle, _ToggledColorC, _ToggledColorD, 90.0F);
            }

            // Fill inside background gradient
            G.FillPath(BackgroundLGB, ControlPath);

            // Draw string
            switch (ToggleType)
            {
            case _Type.OnOff:
                if (Toggled)
                {
                    G.DrawString("ON", new Font("Segoe UI", 12, FontStyle.Regular), new SolidBrush(_ToggledOnOffColorA), Bar.X + 18, (float)(Bar.Y + 13.5), new StringFormat()
                    {
                        Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center
                    });
                }
                else
                {
                    G.DrawString("OFF", new Font("Segoe UI", 12, FontStyle.Regular), new SolidBrush(_ToggledOnOffColorB), Bar.X + 59, (float)(Bar.Y + 13.5), new StringFormat()
                    {
                        Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center
                    });
                }
                break;

            case _Type.YesNo:
                if (Toggled)
                {
                    G.DrawString("YES", new Font("Segoe UI", 12, FontStyle.Regular), new SolidBrush(_ToggledYesNoColorA), Bar.X + 18, (float)(Bar.Y + 13.5), new StringFormat()
                    {
                        Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center
                    });
                }
                else
                {
                    G.DrawString("NO", new Font("Segoe UI", 12, FontStyle.Regular), new SolidBrush(_ToggledYesNoColorB), Bar.X + 59, (float)(Bar.Y + 13.5), new StringFormat()
                    {
                        Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center
                    });
                }
                break;

            case _Type.IO:
                if (Toggled)
                {
                    G.DrawString("I", new Font("Segoe UI", 12, FontStyle.Regular), new SolidBrush(_ToggledIOColorA), Bar.X + 18, (float)(Bar.Y + 13.5), new StringFormat()
                    {
                        Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center
                    });
                }
                else
                {
                    G.DrawString("O", new Font("Segoe UI", 12, FontStyle.Regular), new SolidBrush(_ToggledIOColorB), Bar.X + 59, (float)(Bar.Y + 13.5), new StringFormat()
                    {
                        Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center
                    });
                }
                break;
            }

            Rectangle           SwitchRectangle = new Rectangle(SwitchXLoc, 0, Width - 38, Height);
            GraphicsPath        SwitchPath      = RoundRectangle.RoundRect(SwitchRectangle, 4);
            LinearGradientBrush SwitchButtonLGB = new LinearGradientBrush(SwitchRectangle, _ToggledBackColorA, _ToggledBackColorB, LinearGradientMode.Vertical);

            // Fill switch background gradient
            G.FillPath(SwitchButtonLGB, SwitchPath);

            // Draw borders
            if (_Toggled == true)
            {
                G.DrawPath(new Pen(_ToggledBorderColorA), SwitchPath);
                G.DrawPath(new Pen(_ToggledBorderColorB), ControlPath);
            }
            else
            {
                G.DrawPath(new Pen(_ToggledBorderColorC), SwitchPath);
                G.DrawPath(new Pen(_ToggledBorderColorD), ControlPath);
            }
        }
Ejemplo n.º 10
0
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            Bitmap   B = new Bitmap(Width, Height);
            Graphics G = Graphics.FromImage(B);

            G.Clear(Color.Transparent);
            G.SmoothingMode = SmoothingMode.HighQuality;

            GP1 = RoundRectangle.RoundRect(new Rectangle(0, 0, Width - 1, Height - 1), 4);
            GP2 = RoundRectangle.RoundRect(new Rectangle(1, 1, Width - 3, Height - 3), 4);

            R1 = new Rectangle(0, 2, Width - 1, Height - 1);
            //GB1 = new LinearGradientBrush(R1, Color.FromArgb(255, 255, 255), Color.FromArgb(230, 230, 230), 90f);

            // Draw inside background
            G.FillRectangle(new SolidBrush(_BackColorA), R1);
            G.SetClip(GP1);
            G.FillPath(new SolidBrush(_BackColorB), RoundRectangle.RoundRect(new Rectangle(1, 1, Width - 3, Height / 2 - 2), 4));


            I1 = (int)Math.Round(((double)(_Value - _Minimum) / (double)(_Maximum - _Minimum)) * (double)(Width - 3));
            if (I1 > 1)
            {
                GP3 = RoundRectangle.RoundRect(new Rectangle(1, 1, I1, Height - 3), 4);

                R2  = new Rectangle(1, 1, I1, Height - 3);
                GB2 = new LinearGradientBrush(R2, _ProgressColorA, _ProgressColorB, 90f);

                // Fill the value with its gradient
                G.FillPath(GB2, GP3);

                // Draw diagonal lines
                if (_DrawHatch == true)
                {
                    for (var i = 0; i <= (Width - 1) * _Maximum / _Value; i += 20)
                    {
                        G.DrawLine(new Pen(new SolidBrush(_ProgressHatchColor), 10.0F), new Point(Convert.ToInt32(i), 0), new Point((int)(i - 10), Height));
                    }
                }

                G.SetClip(GP3);
                G.SmoothingMode = SmoothingMode.None;
                G.SmoothingMode = SmoothingMode.AntiAlias;
                G.ResetClip();
            }

            // Draw value as a string
            string DrawString = Convert.ToString(Convert.ToInt32(Value)) + "%";

            /*
             *  int textX = (int)(Width - G.MeasureString(DrawString, Font).Width - 1);
             *  int textY = (int)((Height / 2) - (Convert.ToInt32(G.MeasureString(DrawString, Font).Height / 2) - 2));
             */

            if (_ShowPercentage == true)
            {
                switch (ValueAlignment)
                {
                case Alignment.Left:
                    G.DrawString(DrawString, new Font("Segoe UI", 8), new SolidBrush(ForeColor), new Rectangle(0, 0, Width, Height + 2), new StringFormat
                    {
                        Alignment     = StringAlignment.Near,
                        LineAlignment = StringAlignment.Center
                    });
                    break;

                case Alignment.Right:
                    G.DrawString(DrawString, new Font("Segoe UI", 8), new SolidBrush(ForeColor), new Rectangle(0, 0, Width, Height + 2), new StringFormat
                    {
                        Alignment     = StringAlignment.Far,
                        LineAlignment = StringAlignment.Center
                    });
                    break;

                case Alignment.Center:
                    G.DrawString(DrawString, new Font("Segoe UI", 8), new SolidBrush(ForeColor), new Rectangle(0, 0, Width, Height + 2), new StringFormat
                    {
                        Alignment     = StringAlignment.Center,
                        LineAlignment = StringAlignment.Center
                    });
                    break;
                }
            }

            // Draw border
            G.DrawPath(new Pen(_BorderColor), GP2);

            e.Graphics.DrawImage((Image)(B.Clone()), 0, 0);
            G.Dispose();
            B.Dispose();
        }
Ejemplo n.º 11
0
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            Graphics G = e.Graphics;

            G.SmoothingMode = SmoothingMode.HighQuality;
            G.Clear(Parent.BackColor);
            _Width  = Width - 1;
            _Height = Height - 1;

            GraphicsPath GP        = default;
            GraphicsPath GP2       = new GraphicsPath();
            Rectangle    BaseRect  = new Rectangle(0, 0, _Width, _Height);
            Rectangle    ThumbRect = new Rectangle(_Width / 2, 0, 38, _Height);

            G.SmoothingMode     = (SmoothingMode)2;
            G.PixelOffsetMode   = (PixelOffsetMode)2;
            G.TextRenderingHint = (TextRenderingHint)5;
            G.Clear(BackColor);

            GP        = RoundRectangle.RoundRect(BaseRect, 4);
            ThumbRect = new Rectangle(4, 4, 36, _Height - 8);
            GP2       = RoundRectangle.RoundRect(ThumbRect, 4);
            G.FillPath(new SolidBrush(Color.FromArgb(66, 76, 85)), GP);
            G.FillPath(new SolidBrush(Color.FromArgb(32, 41, 50)), GP2);

            if (_Toggled)
            {
                GP        = RoundRectangle.RoundRect(BaseRect, 4);
                ThumbRect = new Rectangle((_Width / 2) - 2, 4, 36, _Height - 8);
                GP2       = RoundRectangle.RoundRect(ThumbRect, 4);
                G.FillPath(new SolidBrush(Color.FromArgb(32, 34, 37)), GP);
                G.FillPath(new SolidBrush(Color.FromArgb(32, 41, 50)), GP2);
            }

            // Draw string
            switch (ToggleType)
            {
            case _Type.CheckMark:
                if (Toggled)
                {
                    G.DrawString("ü", new Font("Wingdings", 18, FontStyle.Regular), Brushes.WhiteSmoke, Bar.X + 18, Bar.Y + 19, new StringFormat()
                    {
                        Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center
                    });
                }
                else
                {
                    G.DrawString("r", new Font("Marlett", 14, FontStyle.Regular), Brushes.DimGray, Bar.X + 59, Bar.Y + 18, new StringFormat()
                    {
                        Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center
                    });
                }
                break;

            case _Type.OnOff:
                if (Toggled)
                {
                    G.DrawString("ON", new Font("Microsoft Sans Serif", 12, FontStyle.Regular), Brushes.WhiteSmoke, Bar.X + 18, Bar.Y + 16, new StringFormat()
                    {
                        Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center
                    });
                }
                else
                {
                    G.DrawString("OFF", new Font("Microsoft Sans Serif", 12, FontStyle.Regular), Brushes.DimGray, Bar.X + 57, Bar.Y + 16, new StringFormat()
                    {
                        Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center
                    });
                }
                break;

            case _Type.YesNo:
                if (Toggled)
                {
                    G.DrawString("YES", new Font("Microsoft Sans Serif", 12, FontStyle.Regular), Brushes.WhiteSmoke, Bar.X + 19, Bar.Y + 16, new StringFormat()
                    {
                        Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center
                    });
                }
                else
                {
                    G.DrawString("NO", new Font("Microsoft Sans Serif", 12, FontStyle.Regular), Brushes.DimGray, Bar.X + 56, Bar.Y + 16, new StringFormat()
                    {
                        Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center
                    });
                }
                break;

            case _Type.IO:
                if (Toggled)
                {
                    G.DrawString("I", new Font("Microsoft Sans Serif", 12, FontStyle.Regular), Brushes.WhiteSmoke, Bar.X + 18, Bar.Y + 16, new StringFormat()
                    {
                        Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center
                    });
                }
                else
                {
                    G.DrawString("O", new Font("Microsoft Sans Serif", 12, FontStyle.Regular), Brushes.DimGray, Bar.X + 57, Bar.Y + 16, new StringFormat()
                    {
                        Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center
                    });
                }
                break;
            }
        }