Ejemplo n.º 1
0
        private void FormDefine()
        {
            Me.Caption                     = Application.ProductName;
            Me.ShowCaptionBarColor         = false;
            Me.EnableCaptionBarTransparent = false;
            Me.Theme      = Theme.Black;
            Me.ThemeColor = ColorManipulation.GetRandomColorX();

            Me.Loading           += Me_Loading;
            Me.Loaded            += Me_Loaded;
            Me.Closed            += Me_Closed;
            Me.Resize            += Me_Resize;
            Me.SizeChanged       += Me_SizeChanged;
            Me.ThemeChanged      += Me_ThemeChanged;
            Me.ThemeColorChanged += Me_ThemeChanged;
        }
Ejemplo n.º 2
0
        private void _UpdateTrackBarImage()
        {
            if (_TrackBarImage != null)
            {
                _TrackBarImage.Dispose();
            }

            RectangleF wholeBounds    = _WholeBounds;
            RectangleF trackBarBounds = _TrackBarBounds;

            _TrackBarImage = new Bitmap(Math.Max(1, (int)wholeBounds.Width), Math.Max(1, (int)wholeBounds.Height));

            using (Graphics Grap = Graphics.FromImage(_TrackBarImage))
            {
                Color meaningfulBackColor = _MeaningfulBackColor;

                //

                Grap.SmoothingMode = SmoothingMode.AntiAlias;

                Grap.Clear(meaningfulBackColor);

                //

                int ColorNum = (_Colors == null ? 0 : _Colors.Length);

                //

                RectangleF BarImgBounds = new RectangleF(trackBarBounds.Location, new SizeF(Math.Max(1, trackBarBounds.Width), Math.Max(1, trackBarBounds.Height)));

                //

                Color BarBorderColor = ColorManipulation.ShiftLightnessByHSL(meaningfulBackColor, -0.3);

                using (Pen Pn = new Pen(Color.FromArgb(64, BarBorderColor), 2))
                {
                    Grap.DrawRectangles(Pn, new RectangleF[] { new RectangleF(new PointF(BarImgBounds.X - 1, BarImgBounds.Y - 1), new SizeF(BarImgBounds.Width + 2, BarImgBounds.Height + 2)) });
                }

                using (Pen Pn = new Pen(Color.FromArgb(128, BarBorderColor), 2))
                {
                    Grap.DrawRectangles(Pn, new RectangleF[] { BarImgBounds });
                }

                using (Brush Br = new SolidBrush(meaningfulBackColor))
                {
                    Grap.FillRectangle(Br, BarImgBounds);
                }

                //

                if (ColorNum > 0)
                {
                    if (ColorNum == 1)
                    {
                        using (SolidBrush Br = new SolidBrush(_Colors[0]))
                        {
                            Grap.FillRectangle(Br, BarImgBounds);
                        }
                    }
                    else
                    {
                        SizeF SubImgSize = new SizeF(BarImgBounds.Width / (ColorNum - 1) + 0.5F, BarImgBounds.Height);

                        for (int i = 1; i < ColorNum; i++)
                        {
                            RectangleF SubImgBounds = new RectangleF(new PointF(BarImgBounds.X + BarImgBounds.Width * (i - 1) / (ColorNum - 1), BarImgBounds.Y), SubImgSize);

                            using (LinearGradientBrush Br = new LinearGradientBrush(new PointF(SubImgBounds.Left - 0.5F, SubImgBounds.Top), new PointF(SubImgBounds.Right + 0.5F, SubImgBounds.Top), _Colors[i - 1], _Colors[i]))
                            {
                                Grap.FillRectangle(Br, SubImgBounds);
                            }
                        }
                    }
                }

                //

                if (Geometry.CursorIsInControl(Panel_Main) || _MousePressed)
                {
                    using (Brush Br = new SolidBrush(Color.FromArgb(64, Color.White)))
                    {
                        Grap.FillRectangle(Br, BarImgBounds);
                    }
                }

                //

                Color SliderBorderColor = ColorManipulation.ShiftLightnessByHSL(meaningfulBackColor, -0.6);

                Color SliderColor;

                if (ColorNum > 0)
                {
                    if (ColorNum == 1)
                    {
                        SliderColor = _Colors[0];
                    }
                    else
                    {
                        double Pct = (_Value - _Minimum) / (_Maximum - _Minimum);

                        int ColorIndex = (int)Math.Ceiling(Pct * (ColorNum - 1));

                        if (ColorIndex == 0)
                        {
                            ColorIndex = 1;
                        }

                        double SubPct = (double)(ColorIndex - 1) / (ColorNum - 1);

                        double Prop = (Pct - SubPct) * (ColorNum - 1);

                        SliderColor = ColorManipulation.BlendByRGB(_Colors[ColorIndex], _Colors[ColorIndex - 1], Prop);
                    }
                }
                else
                {
                    SliderColor = meaningfulBackColor;
                }

                SliderColor = ColorManipulation.ShiftLightnessByHSL(SliderColor, +0.6);

                float SliderX      = (_Minimum == _Maximum ? trackBarBounds.X : (float)(trackBarBounds.X + (_Value - _Minimum) / (_Maximum - _Minimum) * trackBarBounds.Width));
                float SliderHeight = 0.2F * wholeBounds.Height;

                PointF[] PolygonTop = new PointF[] {
                    new PointF(SliderX, wholeBounds.Y + 1 + SliderHeight),
                    new PointF(SliderX - SliderHeight, wholeBounds.Y + 1),
                    new PointF(SliderX + SliderHeight, wholeBounds.Y + 1)
                };
                PointF[] PolygonBottom = new PointF[] {
                    new PointF(SliderX, wholeBounds.Bottom - 1 - SliderHeight),
                    new PointF(SliderX - SliderHeight, wholeBounds.Bottom - 1),
                    new PointF(SliderX + SliderHeight, wholeBounds.Bottom - 1)
                };

                using (Pen Pn = new Pen(Color.FromArgb(128, SliderBorderColor), 3))
                {
                    Grap.DrawLine(Pn, new PointF(SliderX, trackBarBounds.Y), new PointF(SliderX, trackBarBounds.Bottom));
                }

                using (Pen Pn = new Pen(Color.FromArgb(128, SliderBorderColor), 2))
                {
                    Grap.DrawPolygon(Pn, PolygonTop);
                    Grap.DrawPolygon(Pn, PolygonBottom);
                }

                using (Pen Pn = new Pen(SliderColor, 1))
                {
                    Grap.DrawLine(Pn, new PointF(SliderX, trackBarBounds.Y), new PointF(SliderX, trackBarBounds.Bottom));
                }

                using (Brush Br = new SolidBrush(SliderColor))
                {
                    Grap.FillPolygon(Br, PolygonTop);
                    Grap.FillPolygon(Br, PolygonBottom);
                }
            }
        }