Ejemplo n.º 1
0
        private void Button_draw_2D_Click(object sender, EventArgs e)
        {
            string exp = textBox_exp_2D.Text;

            if (exp == "")
            {
                MessageBox.Show("请输入表达式。");
                return;
            }
            try
            {
                Function.Function func = new Function.Function(exp);
                Caculate2D = func.GetValue;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return;
            }
            if (Max_2D <= Min_2D)
            {
                MessageBox.Show("定义域输入不合法。");
                return;
            }
            Bitmap bitmap = new Bitmap(pictureBox_2D.Width, pictureBox_2D.Height);

            using (Graphics g = Graphics.FromImage(bitmap))
            {
                painter2D = new Painter2D(pictureBox_2D, g, pen_2D, Caculate2D, Min_2D, Max_2D);
                try
                {
                    painter2D.Draw();
                    pictureBox_2D.Image = bitmap;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
            ShowXY_2D = true;
        }
Ejemplo n.º 2
0
        private void Button_draw_Click(object sender, EventArgs e)
        {
            //try
            //{
            //    minX = double.Parse(textBox_min.Text);
            //    maxX = double.Parse(textBox_max.Text);
            //}
            //catch (Exception ex)
            //{
            //    MessageBox.Show(ex.Message);
            //    return;
            //}
            if (maxX <= minX)
            {
                MessageBox.Show("数值输入不合法。");
                return;
            }
            //DrawFunction();
            Bitmap   bitmap = new Bitmap(pictureBox.Width, pictureBox.Height);
            Graphics g      = Graphics.FromImage(bitmap);

            painter = new Painter2D(pictureBox, g, mypen, Caculate, minX, maxX);
            try
            {
                painter.Draw();
                pictureBox.Image = bitmap;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                g.Dispose();
            }
            ShowXY = true;
        }