Example #1
0
        private void drawRedCurve(object sender, PaintEventArgs e, ConvertValueToPixel xMapFunc, ConvertValueToPixel yMapFunc)
        {
            int      i = 0;
            Point    p1 = new Point(), p2 = new Point();
            Graphics gr = e.Graphics;

            // Draw Graph
            // red curve
            // y axis is Angle smoll bush
            double x1, y1;

            // fist we find first non empty text pair

            for (i = 15; i > 0; i--)
            {
                TextBox tbx1  = (Controls.Find("textBoxX1_" + i.ToString(), true)[0] as TextBox);
                TextBox tby11 = (Controls.Find("textBoxY11_" + i.ToString(), true)[0] as TextBox);

                if (tby11.Text == "" || tbx1.Text == "")
                {
                    continue;
                }

                x1 = Convert.ToSingle(tbx1.Text);
                y1 = Convert.ToSingle(tby11.Text);

                x1 = xMapFunc(x1);
                y1 = yMapFunc(y1);

                p1 = new Point((int)x1, (int)(y1));

                break;
            }

            for (int j = i - 1; j > 0; j--)
            {
                TextBox tbx1  = (Controls.Find("textBoxX1_" + j.ToString(), true)[0] as TextBox);
                TextBox tby11 = (Controls.Find("textBoxY11_" + j.ToString(), true)[0] as TextBox);

                if (tby11.Text == "" || tbx1.Text == "")
                {
                    continue;
                }

                double x2 = Convert.ToDouble(tbx1.Text);
                double y2 = Convert.ToDouble(tby11.Text);

                x2 = xMapFunc(x2);
                y2 = yMapFunc(y2);

                p2 = new Point((int)x2, (int)(y2));
                gr.DrawLine(new Pen(Color.Red, 2.0f), p1, p2);

                gr.FillEllipse(Brushes.Black, (int)p1.X - 2, p1.Y - 2, 4, 4);
                gr.FillEllipse(Brushes.Black, (int)p2.X - 2, p2.Y - 2, 4, 4);

                p1 = p2;
            }
        }
Example #2
0
        private void drawBlueCurve(object sender, PaintEventArgs e, ConvertValueToPixel xMapFunc, ConvertValueToPixel yMapFunc)
        {
            double top = paneGraph.Height - 1;

            int      i = 0;
            Point    p1 = new Point(), p2 = new Point();
            Graphics gr = e.Graphics;
            double   x1, y1;

            //blue curve
            for (i = 13; i > 0; i--)
            {
                TextBox tbx2  = (Controls.Find("textBoxX2_" + i.ToString(), true)[0] as TextBox);
                TextBox tby21 = (Controls.Find("textBoxY21_" + i.ToString(), true)[0] as TextBox);

                if (tby21.Text == "" || tbx2.Text == "")
                {
                    continue;
                }

                x1 = Convert.ToSingle(tbx2.Text);
                y1 = Convert.ToSingle(tby21.Text);

                x1 = xMapFunc(x1);
                y1 = yMapFunc(y1);

                p1 = new Point((int)x1, (int)(y1));
                break;
            }

            for (int j = i - 1; j > 0; j--)
            {
                TextBox tbx2  = (Controls.Find("textBoxX2_" + j.ToString(), true)[0] as TextBox);
                TextBox tby21 = (Controls.Find("textBoxY21_" + j.ToString(), true)[0] as TextBox);

                if (tby21.Text == "" || tbx2.Text == "")
                {
                    continue;
                }

                double x2 = Convert.ToDouble(tbx2.Text);
                double y2 = Convert.ToDouble(tby21.Text);

                x2 = xMapFunc(x2);
                y2 = yMapFunc(y2);

                p2 = new Point((int)x2, (int)(y2));
                gr.DrawLine(new Pen(Color.Blue, 2.0f), p1, p2);

                gr.FillEllipse(Brushes.Black, (int)p1.X - 2, p1.Y - 2, 4, 4);
                gr.FillEllipse(Brushes.Black, (int)p2.X - 2, p2.Y - 2, 4, 4);

                p1 = p2;
            }
        }
Example #3
0
        private void graphPanel_Paint(object sender, PaintEventArgs e)  //draw grid and graph
        {
            double gridWidth  = 9;
            double gridHeight = 9;

            drawGrid(sender, e, gridWidth, gridHeight);

            ConvertValueToPixel xMapFunc = new ConvertValueToPixel(convertXToPixel);
            ConvertValueToPixel yAngleSmallBushMapFunc = new ConvertValueToPixel(convertYAngleSmallBushValueToPixel);
            ConvertValueToPixel yAngleLargeBushMapFunc = new ConvertValueToPixel(convertYAngleLargeBushValueToPixel);

            drawRedCurve(sender, e, xMapFunc, yAngleSmallBushMapFunc);
            drawGreenCurve(sender, e, xMapFunc, yAngleLargeBushMapFunc);
            drawBlueCurve(sender, e, xMapFunc, yAngleSmallBushMapFunc);
            drawYellowCurve(sender, e, xMapFunc, yAngleLargeBushMapFunc);
        }