コード例 #1
0
        /// <summary>
        /// Draws the grid center middle of the region.
        /// </summary>
        public static void Draw(ColorGridStyle style, Graphics graphics, Size drawRegion, bool enabled)
        {
            float cellDim  = GetCellDimension(style, drawRegion);
            float xOffset  = (drawRegion.Width / 2f) - style.Colors.GetLength(0) * cellDim / 2;
            float yOffset  = (drawRegion.Height / 2f) - style.Colors.GetLength(1) * cellDim / 2;
            float spacing  = style.CellSpacingScale * cellDim;
            var   master   = GetMasterRectangle(style, drawRegion);
            var   backPath = RoundedRectangleF.Create(master, style.RoundedRadius);

            graphics.FillPath(enabled ? Brushes.Black : Brushes.DimGray, backPath);

            for (int row = 0; row < style.Colors.GetLength(0); row++)
            {
                for (int clm = 0; clm < style.Colors.GetLength(1); clm++)
                {
                    float dim   = cellDim - spacing * 2;
                    var   brush = new SolidBrush(style.Colors[clm, row]);
                    if (!enabled)
                    {
                        brush.Color = brush.Color.Desaturate();
                    }
                    float x    = (xOffset + cellDim * row) + spacing;
                    float y    = (yOffset + cellDim * clm) + spacing;
                    var   path = RoundedRectangleF.Create(x, y, dim, dim, style.RoundedRadius);
                    graphics.FillPath(brush, path);
                    brush.Dispose();
                }
            }
        }
コード例 #2
0
        protected override void OnPaint(PaintEventArgs e)
        {
            e.Graphics.SmoothingMode   = SmoothingMode.AntiAlias;
            e.Graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
            e.Graphics.Clear(GetBackColor());
            ColorGridRendering.Draw(Style, e.Graphics, ClientSize, Enabled);

            if (ClickMode == ClickMode.ColorSet && hoveredRect != Rectangle.Empty)
            {
                var path = RoundedRectangleF.Create(hoveredRect, RoundedRadius);
                Pen pen  = new Pen(Color.White, 3f);
                pen.Alignment = PenAlignment.Center;
                e.Graphics.DrawPath(pen, path);
                pen.Dispose();
            }
            else if (ClickMode == ClickMode.Rotation)
            {
                var rect = ColorGridRendering.GetMasterRectangle(Style, Size);

                if (rect.Contains(PointToClient(Cursor.Position)))
                {
                    ControlPaint.DrawBorder3D(e.Graphics, Rectangle.Truncate(rect),
                                              Border3DStyle.Flat);
                }
            }
        }
 protected override void OnResize(EventArgs e)
 {
     Width    = (Height - 2) * 2;
     diameter = Width / 2;
     artis    = 4 * diameter / 30;
     rect     = new RoundedRectangleF(2 * diameter, diameter + 2, diameter / 2, 1, 1);
     circle   = new RectangleF(!isOn ? 1 : Width - diameter - 1, 1, diameter, diameter);
     base.OnResize(e);
 }
        public ToggleSwitchOriginal()
        {
            Cursor         = Cursors.Hand;
            DoubleBuffered = true;

            artis       = 4; //increment for sliding animation
            diameter    = 30;
            textEnabled = true;
            rect        = new RoundedRectangleF(2 * diameter, diameter + 2, diameter / 2, 1, 1);
            circle      = new RectangleF(1, 1, diameter, diameter);
            isOn        = true;
            borderColor = Color.LightGray;

            paintTicker.Tick    += paintTicker_Tick;
            paintTicker.Interval = 1;
        }
コード例 #5
0
ファイル: Dragger.cs プロジェクト: ssor/csharpDemos
        public virtual void draw(Graphics g)
        {
            Pen p = new Pen(Color.White);
            RoundedRectangleF outLayer = new RoundedRectangleF(_location.X, _location.Y, _width, _height, 1);
            GraphicsPath      gp       = new GraphicsPath();

            gp.AddPath(outLayer.GetGraphicsPath(), false);
            outLayer.Shrink(3);
            gp.AddPath(outLayer.GetGraphicsPath(), false);
            // Border.Border border = new Border.BorderShadow();
            //  border.DrawBorder(g, gp);
            GraphicsState state = g.Save();

            g.TranslateTransform(5, 1);
            g.FillPath(new SolidBrush(Color.FromArgb(150, Color.Black)), gp);
            g.Restore(state);
            PathGradientBrush pgb = new PathGradientBrush(gp);

            if (_mouseHover || _mouseDown)
            {
                pgb.CenterColor    = _normalColor;
                pgb.SurroundColors = new Color[] { _selectColor };
            }
            else
            {
                pgb.CenterColor    = _selectColor;
                pgb.SurroundColors = new Color[] { _normalColor };
            }
            Pen pointer = new Pen(_pointerColor, 4);

            pointer.StartCap = LineCap.DiamondAnchor;
            pointer.EndCap   = LineCap.DiamondAnchor;
            g.DrawLine(new Pen(Color.FromArgb(150, Color.Black), 3), new PointF(_location.X + _width / 2 + 2, _parentY - 7), new PointF(_location.X + _width / 2 + 2, _parentY + _height - 4));
            g.DrawLine(pointer, new PointF(_location.X + _width / 2, _parentY - 5), new PointF(_location.X + _width / 2, _parentY + _height - 2));
            g.FillPath(pgb, gp);
            g.DrawPath(p, gp);
            pgb.Dispose();
            p.Dispose();
        }