Cześć!
Na starcie zaznaczam, że uczę się programować od 0.
Napisałem samodzielnie już kod do Forms'a, w pełni sprawny, ale chcę dorobić jeszcze takie opcje:
- liczenie pierwiastków zespolonych klikając (RadioButton) w nowym okienku (new Form, ShowDialog)
- ustawienie skrótów klawiszowych Alt+a, Alt+b, Alt+c dla pól ze współczynnikami.
Do teraz w kwestii 1 myślnika mam:
if (cb_showComplexRoots.Checked == true)
{
ComplexRootsForm cr = new ComplexRootsForm(a, b, delta);
cr.ShowDialog();
}
wiem, że muszę ustawić nowy form, ale nwm jak to zrobić, żeby działało.
Z tym 2 myślnikiem też nie wykminiłem.
Bardzo byłbym wdzięczny za jakieś pomoce.
Dotychczasowy kod + zdjęcie:
public partial class Form1 : Form
{
private double a, b, c, delta, x = 0;
private double x1, x2 = 0;
private void richTextBox2_TextChanged(object sender, EventArgs e)
{
}
private void richTextBox1_TextChanged(object sender, EventArgs e)
{
}
public Form1()
{
InitializeComponent();
}
private void richTextBox3_TextChanged(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
if (IsDataValidationOK())
{
delta = b * b - 4.0 * a * c;
if (delta < 0)
{
textBox2.Text = "Brak";
textBox3.Text = "Brak";
textBox1.Text = delta.ToString();
/* if (cb_showComplexRoots.Checked == true)
{
ComplexRootsForm cr = new ComplexRootsForm(a, b, delta);
cr.ShowDialog();
}*/
}
else if (delta == 0)
{
x = -b / (2.0 * a);
textBox2.Text = Math.Round(x, 4).ToString();
textBox3.Text = "Brak";
textBox1.Text = delta.ToString();
}
else
{
x1 = (-b - Math.Sqrt(delta)) / (2.0 * a);
x2 = (-b + Math.Sqrt(delta)) / (2.0 * a);
textBox2.Text = Math.Round(x1, 4).ToString();
textBox3.Text = Math.Round(x2, 4).ToString();
textBox1.Text = delta.ToString();
}
}
else
{
ClearResultFields();
}
}
private bool IsDataValidationOK()
{
bool testOK = true;
if (!Double.TryParse(richTextBox1.Text, out a))
{
MessageBox.Show("Wartość a nie jest liczbą!");
testOK = false;
}
else if (a == 0)
{
MessageBox.Show("Równanie sprzeczne: a nie moze być równe 0!");
testOK = false;
}
if (!Double.TryParse(richTextBox2.Text, out b))
{
MessageBox.Show("Wartość b nie jest liczbą!");
testOK = false;
}
if (!Double.TryParse(richTextBox3.Text, out c))
{
MessageBox.Show("Wartość c nie jest liczbą!");
testOK = false;
}
return testOK;
}
private void label3_Click(object sender, EventArgs e)
{
}
private void label4_Click(object sender, EventArgs e)
{
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void checkBox1_CheckedChanged_1(object sender, EventArgs e)
{
ClearResultFields();
textBox2.Text = "";
textBox3.Text = "";
textBox1.Text = "";
richTextBox2.Text = "";
richTextBox1.Text = "";
richTextBox3.Text = "";
}
private void ClearResultFields()
{
textBox2.Text = "";
textBox3.Text = "";
}
private void label1_Click(object sender, EventArgs e)
{
}
private void label2_Click(object sender, EventArgs e)
{
}
private void radioButton1_CheckedChanged(object sender, EventArgs e)
{
}
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
}
}
}
Grafika:
- Zrzut ekranu (1056).png (8 KB) - ściągnięć: 10