Anda di halaman 1dari 4

using using using using using using using using using

System; System.Collections.Generic; System.ComponentModel; System.Data; System.Drawing; System.Linq; System.Text; System.Windows.Forms; ZedGraph;

namespace WindowsFormsApplication1 { public partial class Form1 : Form { double alpha; string string double double double double double signos = ""; signoc = ""; a; b; c; x2; x;

public Form1() { InitializeComponent(); }

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 {

listBox1.Items.Add(Convert.ToString(a) + "x^2" + signos + Convert.ToString(b) + "x" ); }

} private void button4_Click(object sender, EventArgs e) {

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);

} else textBox6.Text = Convert.ToString(a) + "x^2" + signos + Convert.ToString(b) + "x" ;

//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++) {

double y = (a*(i*i))+(b*i)+c; spl1.Add(i, y);

} //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 listBox1_MouseDoubleClick(object sender, MouseEventArgs e) { listBox1.Items.Remove(listBox1.SelectedItems[0]);

} 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) {

} private void listBox1_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { textBox6.Text = listBox1.SelectedItem.ToString();

// textBox1.Text = a.ToString(); //textBox2.Text = b.ToString(); //textBox3.Text = c.ToString(); }

} }