private void PaintOneLevel(Graphics canvas, Rectangle rectPaint, decimal Value, int index) { rectPaint = RectanglePaint.DeleteRight(rectPaint, new Rectangle(0, 0, this.PanelValues.WidthBorder, 0)); int Y1 = GraphicShape.GetCoordinate(rectPaint.Height, this.Max, this.Min, Value > 0 ? Value : 0); int Y2 = GraphicShape.GetCoordinate(rectPaint.Height, this.Max, this.Min, Value < 0 ? Value : 0); int bodyX = (int)(rectPaint.Width - this.WidthOneLevel * index); int bodyY = rectPaint.Y + Y1; int bodyWidth = this.WidthOneLevel - 2; //-2 чтобы свечки не слипались int bodyHeight = Y2 - Y1; //bodyHeight = bodyHeight - bodyY; bodyHeight = bodyHeight == 0 ? bodyHeight + 1 : bodyHeight; GraphicShape.PaintRectangle(canvas, bodyX, bodyY, bodyWidth, bodyHeight, Color.Black, Value < 0 ? Color.Red : Color.Green); }
/// <summary> Рисует одну свечку </summary> /// <param name="canvas"></param> /// <param name="rectPaint"></param> /// <param name="candleData"></param> /// <param name="index"></param> /// <param name="maxPrice"></param> /// <param name="minPrice"></param> private void PaintOneCandle(Graphics canvas, Rectangle rectPaint, CandleLib.CandleData candleData, int index, decimal maxPrice, decimal minPrice) { int tailY1 = GraphicShape.GetCoordinate(rectPaint.Height, maxPrice, minPrice, candleData.High); int tailY2 = GraphicShape.GetCoordinate(rectPaint.Height, maxPrice, minPrice, candleData.Low); int tailX1 = (int)((rectPaint.Width - this.WidthOneCandle * index) + this.WidthOneCandle / 2); int bodyX = (int)(rectPaint.Width - this.WidthOneCandle * index); int bodyY = GraphicShape.GetCoordinate(rectPaint.Height, maxPrice, minPrice, candleData.Open > candleData.Close ? candleData.Open : candleData.Close); int bodyWidth = this.WidthOneCandle - MarginCandle; //- чтобы свечки не слипались int bodyHeight = GraphicShape.GetCoordinate(rectPaint.Height, maxPrice, minPrice, candleData.Open < candleData.Close ? candleData.Open : candleData.Close); bodyHeight = bodyHeight - bodyY; bodyHeight = bodyHeight == 0 ? bodyHeight + 1 : bodyHeight; GraphicShape.PaintLine(canvas, new Point(tailX1, tailY1), new Point(tailX1, tailY2), Color.Black, 2); GraphicShape.PaintRectangle(canvas, bodyX, bodyY, bodyWidth, bodyHeight, Color.Black, candleData.Open > candleData.Close ? Color.LightCoral : Color.LightGreen); if (OnPaintCandle != null) { OnPaintCandle(new DataCandle() { PaintRect = rectPaint, Candle = candleData, TailCoord = new TailCoord() { High = new Point(tailX1, tailY1), Low = new Point(tailX1, tailY2) }, Body = new Rectangle() { X = bodyX, Y = bodyY, Width = bodyWidth, Height = bodyHeight }, Index = index }); } }