Forex_Strategy_Builder.Small_Indicator_Chart.OnPaint C# (CSharp) Метод

OnPaint() защищенный Метод

Paints the chart
protected OnPaint ( PaintEventArgs e ) : void
e PaintEventArgs
Результат void
        protected override void OnPaint(PaintEventArgs e)
        {
            Graphics g = e.Graphics;
            Data.GradientPaint(g, new Rectangle(border, (int)captionHeight, ClientSize.Width - 2 * border, ClientSize.Height - (int)captionHeight - border),
                LayoutColors.ColorChartBack, LayoutColors.DepthControl);

            // Panel caption
            Data.GradientPaint(g, rectfCaption, LayoutColors.ColorCaptionBack, LayoutColors.DepthCaption);
            g.DrawString(stringCaptionText, fontCaptionText, brushCaptionText, rectfCaption, stringFormatCaption);

            // Border
            g.DrawLine(penBorder, 1, captionHeight, 1, ClientSize.Height);
            g.DrawLine(penBorder, ClientSize.Width - border + 1, captionHeight, ClientSize.Width - border + 1, ClientSize.Height);
            g.DrawLine(penBorder, 0, ClientSize.Height - border + 1, ClientSize.Width, ClientSize.Height - border + 1);

            if (!Data.IsData || !Data.IsResult || Data.Bars <= Data.FirstBar) return;

            // Limits the drawing into the chart area only
            g.SetClip(new Rectangle(xLeft, yTop, xRight - xLeft, yPrcBottom - yTop));

            // Draws Volume, Lots and Price
            int index = 0;
            Pen penBar = new Pen(LayoutColors.ColorBarBorder);
            for (bar = firstBar; bar <= lastBar; bar++)
            {
                // Draw the volume
                if (yVolume[index] != yPrcBottom)
                    g.DrawLine(penVolume, x[index], yVolume[index], x[index], yPrcBottom - 1);

                // Draw position lots
                if (rectPosition[index] != Rectangle.Empty)
                    g.FillRectangle(brushPosition[index], rectPosition[index]);

                // Draw the bar
                g.DrawLine(penBar, x[index], yLow[index], x[index], yHigh[index]);
                g.DrawLine(penBar, x[index], yClose[index], x[index] + 1, yClose[index]);
                index++;
            }

            // Drawing the indicators in the chart
            for (int slot = 0; slot < slots; slot++)
            {
                if (bIsSeparatedChart[slot]) continue;
                for (int iComp = 0; iComp < iComponentLenght[slot]; iComp++)
                {
                    if (chartType[slot][iComp] == IndChartType.Line)
                    {   // Line
                        g.DrawLines(new Pen(chartBrush[slot][iComp]), chartLine[slot][iComp]);
                    }
                    else if (chartType[slot][iComp] == IndChartType.Dot)
                    {   // Dots
                        for (bar = firstBar; bar <= lastBar; bar++)
                            g.FillRectangle(chartBrush[slot][iComp], chartDot[slot][iComp][bar - firstBar]);
                    }
                    else if (chartType[slot][iComp] == IndChartType.Level)
                    {   // Level
                        for (bar = firstBar; bar <= lastBar; bar++)
                            g.FillRectangle(chartBrush[slot][iComp], chartLevel[slot][iComp][bar - firstBar]);
                    }
                    else if (chartType[slot][iComp] == IndChartType.CloudUp)
                    {   // CloudUp
                        Pen pen = new Pen(chartBrush[slot][iComp]);
                        pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;
                        g.DrawLines(pen, chartLine[slot][iComp]);
                    }
                    else if (chartType[slot][iComp] == IndChartType.CloudDown)
                    {   // CloudDown
                        Pen pen = new Pen(chartBrush[slot][iComp]);
                        pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;
                        g.DrawLines(pen, chartLine[slot][iComp]);
                    }
                }
            }
            g.ResetClip();

            // Separate indicators
            for (int ind = 0; ind < inds; ind++)
            {
                int slot = aiIndSlot[ind];

                for (int comp = 0; comp < iComponentLenght[slot]; comp++)
                {
                    if (chartType[slot][comp] == IndChartType.Line)
                    {   // Line
                        g.DrawLines(new Pen(chartBrush[slot][comp]), chartLine[slot][comp]);
                    }
                    else if (chartType[slot][comp] == IndChartType.Histogram)
                    {   // Histogram
                        double zero = 0;
                        if (zero < dMinValue[ind]) zero = dMinValue[ind];
                        if (zero > dMaxValue[ind]) zero = dMaxValue[ind];
                        int y0 = (int)(yIndBottom[ind] - (zero - dMinValue[ind]) * dScale[ind]);
                        g.DrawLine(penDarkGray, xLeft, y0, xRight, y0);
                        for (bar = firstBar; bar <= lastBar; bar++)
                        {
                            double val = chartValue[slot][comp][bar - firstBar];
                            int x = (bar - firstBar) * barPixels + xLeft;
                            int y = (int)(yIndBottom[ind] - (val - dMinValue[ind]) * dScale[ind]);
                            g.DrawLine(chartPen[slot][comp][bar - firstBar], x, y0, x, y);
                        }
                    }
                }
            }

            // Lines
            for (int ind = 0; ind < inds; ind++)
            {
                int y = yBottom - (ind + 1) * indHeight;
                g.DrawLine(penFore, xLeft, y, xRight, y);
            }
            g.DrawLine(penFore, xLeft, yBottom, xRight, yBottom);
            g.DrawLine(penFore, xLeft, yTop, xLeft, yBottom);
        }