private void DrawLever(Graphics g, Rectangle clipRectangle) { Point start = new Point(_knobRadius, Height / 2); Rectangle knob = GetKnobBounds(); PointF center = new PointF(knob.X + _knobRadius, knob.Y + _knobRadius); double dx = center.X - start.X; double dy = center.Y - start.Y; double len = Math.Sqrt(dx * dx + dy * dy); double sx = dx / len; double sy = dy / len; PointF kJoint = new PointF((float)(center.X - sx * _knobRadius), (float)(center.Y - sy * _knobRadius)); PointF sJoint = new PointF((float)(center.X - sx * (_knobRadius + _barLength)), (float)(center.Y - sy * (_barLength + _knobRadius))); Pen back = new Pen(BackColor.Darker(.2F), _barWidth); back.EndCap = LineCap.Round; back.StartCap = LineCap.Round; Pen front = new Pen(BackColor, (float)_barWidth / 2); front.EndCap = LineCap.Round; front.StartCap = LineCap.Round; g.DrawLine(back, sJoint, kJoint); g.DrawLine(front, sJoint, kJoint); back.Dispose(); front.Dispose(); }
private void DrawLever(Graphics g, Rectangle clipRectangle) { Point start = new(KnobRadius, Height / 2); Rectangle knob = GetKnobBounds(); PointF center = new(knob.X + KnobRadius, knob.Y + KnobRadius); double dx = center.X - start.X; double dy = center.Y - start.Y; double len = Math.Sqrt((dx * dx) + (dy * dy)); double sx = dx / len; double sy = dy / len; PointF kJoint = new((float)(center.X - (sx * KnobRadius)), (float)(center.Y - (sy * KnobRadius))); PointF sJoint = new((float)(center.X - (sx * (KnobRadius + BarLength))), (float)(center.Y - (sy * (BarLength + KnobRadius)))); Pen back = new(BackColor.Darker(.2F), BarWidth) { EndCap = LineCap.Round, StartCap = LineCap.Round }; Pen front = new(BackColor, (float)BarWidth / 2) { EndCap = LineCap.Round, StartCap = LineCap.Round }; g.DrawLine(back, sJoint, kJoint); g.DrawLine(front, sJoint, kJoint); back.Dispose(); front.Dispose(); }
/// <summary> /// Instructs this button to draw itself. /// </summary> /// <param name="g">The graphics surface to draw to.</param> public void Draw(Graphics g) { if (Bounds.Width == 0 || Bounds.Height == 0) { return; } Pen border = null; Brush fill = null; if (!Selected && !Highlighted) { border = new Pen(Color.Gray); fill = new LinearGradientBrush(Bounds, BackColor.Lighter(.2f), BackColor.Darker(.2f), 45); } if (!Selected && Highlighted) { border = new Pen(Color.FromArgb(216, 240, 250)); fill = new LinearGradientBrush(Bounds, Color.FromArgb(245, 250, 253), Color.FromArgb(232, 245, 253), LinearGradientMode.Vertical); } if (Selected && !Highlighted) { border = new Pen(Color.FromArgb(153, 222, 253)); fill = new LinearGradientBrush(Bounds, Color.FromArgb(241, 248, 253), Color.FromArgb(213, 239, 252), LinearGradientMode.Vertical); } if (Selected && Highlighted) { border = new Pen(Color.FromArgb(182, 230, 251)); fill = new LinearGradientBrush(Bounds, Color.FromArgb(232, 246, 253), Color.FromArgb(196, 232, 250), LinearGradientMode.Vertical); } using (GraphicsPath gp = new GraphicsPath()) { gp.AddRoundedRectangle(Bounds, 2); if (fill != null) { g.FillPath(fill, gp); } if (border != null) { g.DrawPath(border, gp); } } fill?.Dispose(); }
/// <summary> /// Controls the actual drawing for this gradient slider control. /// </summary> /// <param name="g">The graphics object used for drawing.</param> /// <param name="clipRectangle">The clip rectangle.</param> protected virtual void OnDraw(Graphics g, Rectangle clipRectangle) { if (Width == 0 || Height == 0) { return; } LinearGradientBrush lgb = new(ClientRectangle, BackColor.Lighter(.2F), BackColor.Darker(.2F), LinearGradientMode.Vertical); g.FillRectangle(lgb, ClientRectangle); lgb.Dispose(); int l = Convert.ToInt32((Width * (LeftHandle.Position - _min)) / (_max - _min)); int r = Convert.ToInt32((Width * (RightHandle.Position - _min)) / (_max - _min)); Rectangle a = new(0, 5, l, Height - 10); Rectangle b = new(l, 5, r - l, Height - 10); Rectangle c = new(r, 5, Right - r, Height - 10); if (a.Width > 0) { SolidBrush sb = new(_minColor); g.FillRectangle(sb, a); sb.Dispose(); } if (b.Width > 0) { LinearGradientBrush center = new(new Point(b.X, 0), new Point(b.Right, 0), _minColor, _maxColor); g.FillRectangle(center, b); center.Dispose(); } if (c.Width > 0) { SolidBrush sb = new(_maxColor); g.FillRectangle(sb, c); sb.Dispose(); } if (Enabled) { LeftHandle.Draw(g); RightHandle.Draw(g); } }
/// <summary> /// Controls the actual drawing for this gradient slider control. /// </summary> /// <param name="g"></param> /// <param name="clipRectangle"></param> protected virtual void OnDraw(Graphics g, Rectangle clipRectangle) { GraphicsPath gp = new GraphicsPath(); Rectangle innerRect = new Rectangle(_leftHandle.Width, 3, Width - 1 - _rightHandle.Width - _leftHandle.Width, Height - 1 - 6); gp.AddRoundedRectangle(innerRect, 2); if (Width == 0 || Height == 0) { return; } // Create a rounded gradient effect as the backdrop that other colors will be drawn to LinearGradientBrush silver = new LinearGradientBrush(ClientRectangle, BackColor.Lighter(.2F), BackColor.Darker(.6F), LinearGradientMode.Vertical); g.FillPath(silver, gp); silver.Dispose(); LinearGradientBrush lgb = new LinearGradientBrush(innerRect, MinimumColor, MaximumColor, LinearGradientMode.Horizontal); g.FillPath(lgb, gp); lgb.Dispose(); g.DrawPath(Pens.Gray, gp); gp.Dispose(); if (Enabled) { _leftHandle.Draw(g); _rightHandle.Draw(g); } }
private void DrawColorSemicircle(Graphics g) { Rectangle bounds = GetSemicircleBounds(); if (bounds.Width <= 0 || bounds.Height <= 0) { return; } GraphicsPath gp = new GraphicsPath(); gp.AddPie(new Rectangle(-bounds.Width, bounds.Y, bounds.Width * 2, bounds.Height), -90, 180); Rectangle roundBounds = new Rectangle(bounds.X, bounds.Y, bounds.Width, bounds.Height); LinearGradientBrush lgb = new LinearGradientBrush(roundBounds, BackColor.Lighter(.5F), BackColor.Darker(.5F), LinearGradientMode.ForwardDiagonal); g.FillPath(lgb, gp); lgb.Dispose(); gp.Dispose(); gp = new GraphicsPath(); Rectangle innerRound = GetInnerSemicircleBounds(); if (innerRound.Width <= 0 || innerRound.Height <= 0) { return; } gp.AddPie(new Rectangle(innerRound.X - innerRound.Width, innerRound.Y, innerRound.Width * 2, innerRound.Height), -90, 180); PointF center = new PointF(innerRound.X + innerRound.Width / 2, innerRound.Y + innerRound.Height / 2); float x = center.X - innerRound.Width; float y = center.Y - innerRound.Height; float w = innerRound.Width * 2; float h = innerRound.Height * 2; RectangleF circum = new RectangleF(x, y, w, h); GraphicsPath coloring = new GraphicsPath(); coloring.AddEllipse(circum); PathGradientBrush pgb = new PathGradientBrush(coloring); pgb.CenterColor = _color.Lighter(.2F); pgb.SurroundColors = new[] { _color.Darker(.2F) }; pgb.CenterPoint = new PointF(innerRound.X + 3, innerRound.Y + innerRound.Height / 3); g.FillPath(pgb, gp); lgb.Dispose(); gp.Dispose(); }
/// <summary> /// Controls the actual drawing for this gradient slider control. /// </summary> /// <param name="g">The graphics object used for drawing.</param> /// <param name="clipRectangle">The clip rectangle.</param> protected virtual void OnDraw(Graphics g, Rectangle clipRectangle) { using (GraphicsPath gp = new()) { Rectangle innerRect = new(LeftHandle.Width, 3, Width - 1 - RightHandle.Width - LeftHandle.Width, Height - 1 - 6); gp.AddRoundedRectangle(innerRect, 2); if (Width == 0 || Height == 0) { return; } // Create a rounded gradient effect as the backdrop that other colors will be drawn to LinearGradientBrush silver = new(ClientRectangle, BackColor.Lighter(.2F), BackColor.Darker(.6F), LinearGradientMode.Vertical); g.FillPath(silver, gp); silver.Dispose(); using (LinearGradientBrush lgb = new(innerRect, Color.White, Color.White, LinearGradientMode.Horizontal)) { Color[] colors = new Color[37]; float[] positions = new float[37]; for (int i = 0; i <= 36; i++) { int j = _inverted ? 36 - i : i; colors[j] = SymbologyGlobal.ColorFromHsl(((i * 10) + _hueShift) % 360, 1, .7).ToTransparent(.7f); positions[i] = i / 36f; } ColorBlend cb = new() { Colors = colors, Positions = positions }; lgb.InterpolationColors = cb; g.FillPath(lgb, gp); } g.DrawPath(Pens.Gray, gp); } if (Enabled) { LeftHandle.Draw(g); RightHandle.Draw(g); } }