namespace WindowsFormsApplication1 { public partial class Form1 : Form { double alpha; string string double double double double double signos = ""; signoc = ""; a; b; c; x2; x;
private void button2_Click(object sender, EventArgs e) { textBox1.Text = ""; textBox2.Text = ""; textBox3.Text = ""; textBox4.Text = ""; textBox5.Text = ""; textBox6.Text = ""; zedGraphControl1.GraphPane.CurveList.Clear();
} private void button3_Click(object sender, EventArgs e) { if (c != 0) { listBox1.Items.Add(Convert.ToString(a) + "x^2" + signos + Convert.ToString(b) + "x" + signoc + Convert.ToString(c) ); //listBox1.Items.Add(textBox6.Text); } else {
try { a = Double.Parse(textBox1.Text); b = Double.Parse(textBox2 .Text); c = Double.Parse(textBox3.Text); if (b <= 0) signos = ""; else signos = "+"; if (c <= 0) signoc = ""; else signoc = "+"; alpha = ((Math.Pow(b, 2)) - (4 * a * c));
if (Math.Sign(alpha) == -1) { alpha = (Math.Sqrt(-alpha)) / (2 * a); x = -b / a; textBox4.Text = x.ToString("0.00") + " - " + alpha.ToString("0.00") + "i"; textBox5.Text = x.ToString("0.00") + "+" + alpha.ToString("0.00") + "i"; } else { alpha = Math.Sqrt(alpha); x = (-b - alpha) / (2 * a); x2 = (-b + alpha) / (2 * a); textBox4.Text = x.ToString("0.00"); textBox5.Text = x2.ToString("0.00"); } } catch { MessageBox.Show(this,"Ingrese un nmero vlido","Error en los datos", MessageBoxButtons.OK,MessageBoxIcon.Warning); } if (c != 0) { textBox6.Text = Convert.ToString(a) + "x^2" + signos + Convert.ToString(b) + "x"+ signoc + Convert.ToString(c);
//grafica zedGraphControl1.GraphPane.CurveList.Clear(); GraphPane myPane = zedGraphControl1.GraphPane; PointPairList spl1 = new PointPairList(); LineItem myCurve1 = myPane.AddCurve("Ecuacin", spl1, Color.Purple, SymbolType.None); myCurve1.Line.Width = 5.0F; myPane.Title.Text = "Grafica"; for (int i = -5; i < 6; i++) {
} //I add all three functions just to be sure it refeshes the plot. zedGraphControl1.AxisChange(); zedGraphControl1.Invalidate(); zedGraphControl1.Refresh(); } private void textBox1_KeyPress(object sender, KeyPressEventArgs e) {
} private void textBox2_KeyPress(object sender, KeyPressEventArgs e) { } private void textBox3_KeyPress(object sender, KeyPressEventArgs e) { } private void textBox6_TextChanged(object sender, EventArgs e) { }
} private void Form1_Load(object sender, EventArgs e) { GraphPane Grafico =zedGraphControl1.GraphPane; //Ttulos de los grficos Grafico.Title.Text ="Ecuacion"; Grafico.XAxis.Title.Text ="Eje x"; Grafico.YAxis.Title.Text = "Eje y"; } private void button1_Click(object sender, EventArgs e) {
} }