예제 #1
0
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            lock (lockObject)
            {
                using (var path = new GraphicsPath())
                    using (var pathPen = new Pen(ForeColor, 3))
                        using (Brush brush = new SolidBrush(Color.FromArgb(130, ForeColor2)))
                        {
                            int lineNum = 0;
                            for (var index = values.Count - 2; index > -1; index -= 1)
                            {
                                var xOffset = DisplayRectangle.Width - (lineNum * 3);
                                lineNum++;

                                var yScale1 = values[index + 1] / (double)YScale;
                                var yScale2 = values[index] / (double)YScale;

                                var y1 = DisplayRectangle.Height - (int)(DisplayRectangle.Height * yScale1);
                                var y2 = DisplayRectangle.Height - (int)(DisplayRectangle.Height * yScale2);

                                path.AddLine(xOffset, y1, xOffset - STEP_LENGTH, y2);

                                if (xOffset < 0)
                                {
                                    break;
                                }
                            }
                            var oldMode = e.Graphics.SmoothingMode;
                            e.Graphics.SmoothingMode     = SmoothingMode.AntiAlias;
                            e.Graphics.TextRenderingHint = TextRenderingHint.AntiAlias;

                            if (showValue)
                            {
                                var stringFormat = new StringFormat();
                                stringFormat.Alignment     = StringAlignment.Center;
                                stringFormat.LineAlignment = StringAlignment.Center;
                                stringFormat.FormatFlags   = StringFormatFlags.NoWrap;

                                var textualValue = values.LastOrDefault().ToString();
                                var fontSize     = TextUtils.GetFontSize(e.Graphics, textualValue, Font, ClientRectangle.Size);

                                e.Graphics.DrawString(textualValue, new Font(Font.FontFamily, fontSize), brush, ClientRectangle, stringFormat);
                            }


                            e.Graphics.DrawPath(pathPen, path);
                            e.Graphics.SmoothingMode = oldMode;
                        }

                ControlPaint.DrawBorder(e.Graphics, ClientRectangle, Color.DarkGray, ButtonBorderStyle.Solid);
            }
        }
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            lock (lockObject)
            {
                using (GraphicsPath path = new GraphicsPath())
                    using (GraphicsPath path2 = new GraphicsPath())
                        using (Pen pathPen = new Pen(ForeColor, 3))
                            using (Pen pathPen2 = new Pen(Color.FromArgb(150, ForeColor), 3))
                                using (Brush brush = new SolidBrush(Color.FromArgb(130, ForeColor2)))
                                {
                                    int   lineNum    = 0;
                                    float xOffset    = ClientRectangle.Width;
                                    float stepLength = ClientRectangle.Width / 2f / (float)(chunkSize - 1);

                                    for (int index = values.Count - 2; index > -1; index -= 1)
                                    {
                                        lineNum++;

                                        float yScale1 = values[index + 1] / (float)YScale;
                                        float yScale2 = values[index] / (float)YScale;

                                        float y1 = ClientRectangle.Height - (ClientRectangle.Height * yScale1);
                                        float y2 = ClientRectangle.Height - (ClientRectangle.Height * yScale2);

                                        path.AddLine(xOffset, y1, xOffset -= stepLength, y2);

                                        if (lineNum == chunkSize)
                                        {
                                            break;
                                        }
                                    }

                                    lineNum = 0;
                                    xOffset = ClientRectangle.Width / 2f;
                                    for (int index = values2.Count - 2; index > -1; index -= 1)
                                    {
                                        lineNum++;

                                        float yScale1 = values2[index + 1] / (float)YScale;
                                        float yScale2 = values2[index] / (float)YScale;

                                        float y1 = ClientRectangle.Height - (ClientRectangle.Height * yScale1);
                                        float y2 = ClientRectangle.Height - (ClientRectangle.Height * yScale2);

                                        path2.AddLine(xOffset, y1, xOffset -= stepLength, y2);

                                        if (lineNum == chunkSize)
                                        {
                                            break;
                                        }
                                    }

                                    e.Graphics.DrawLine(Pens.Blue, ClientRectangle.Width / 2f, 0, ClientRectangle.Width / 2f, ClientRectangle.Bottom);

                                    SmoothingMode oldMode = e.Graphics.SmoothingMode;
                                    e.Graphics.SmoothingMode     = SmoothingMode.AntiAlias;
                                    e.Graphics.TextRenderingHint = TextRenderingHint.AntiAlias;

                                    if (showValue)
                                    {
                                        StringFormat stringFormat = new StringFormat();
                                        stringFormat.Alignment     = StringAlignment.Center;
                                        stringFormat.LineAlignment = StringAlignment.Center;
                                        stringFormat.FormatFlags   = StringFormatFlags.NoWrap;

                                        string textualValue = values.LastOrDefault().ToString();
                                        int    fontSize     = TextUtils.GetFontSize(e.Graphics, textualValue, Font, ClientRectangle.Size);

                                        e.Graphics.DrawString(textualValue, new Font(Font.FontFamily, fontSize), brush, ClientRectangle, stringFormat);
                                    }

                                    e.Graphics.DrawPath(pathPen, path);
                                    e.Graphics.DrawPath(pathPen2, path2);
                                    e.Graphics.SmoothingMode = oldMode;
                                }

                ControlPaint.DrawBorder(e.Graphics, ClientRectangle, Color.DarkGray, ButtonBorderStyle.Solid);
            }
        }