我想知道如何使用messagebox来显示我从计算中获得的逆矩阵。
OOPTools_Math.Matrix Inver = new OOPTools_Math.Matrix(5, 5);
Inver = A.Invert(A);
我的想法是构建新矩阵并从Inver = A.Invert(A)
输入信息,然后使用Messagebox.Show()
。
============================================
我修改了一下
OOPTools_Math.Matrix Inver = new OOPTools_Math.Matrix(5, 5);
Inver = A.Invert(A) ;
string i = Inver.ToString();
MessageBox.Show(i);
=============================================== ==============
这就是我所做的
private void button3_Click(object sender, EventArgs e)
{
OOPTools_Math.Matrix A = new OOPTools_Math.Matrix(5, 5);
A.Values[0, 0] = Convert.ToDouble(textBox1.Text);
A.Values[0, 1] = Convert.ToDouble(textBox2.Text);
A.Values[0, 2] = Convert.ToDouble(textBox3.Text);
A.Values[0, 3] = Convert.ToDouble(textBox4.Text);
A.Values[0, 4] = Convert.ToDouble(textBox5.Text);
A.Values[1, 0] = Convert.ToDouble(textBox6.Text);
A.Values[1, 1] = Convert.ToDouble(textBox7.Text);
A.Values[1, 2] = Convert.ToDouble(textBox8.Text);
A.Values[1, 3] = Convert.ToDouble(textBox9.Text);
A.Values[1, 4] = Convert.ToDouble(textBox10.Text);
A.Values[2, 0] = Convert.ToDouble(textBox11.Text);
A.Values[2, 1] = Convert.ToDouble(textBox12.Text);
A.Values[2, 2] = Convert.ToDouble(textBox13.Text);
A.Values[2, 3] = Convert.ToDouble(textBox14.Text);
A.Values[2, 4] = Convert.ToDouble(textBox15.Text);
A.Values[3, 0] = Convert.ToDouble(textBox16.Text);
A.Values[3, 1] = Convert.ToDouble(textBox17.Text);
A.Values[3, 2] = Convert.ToDouble(textBox18.Text);
A.Values[3, 3] = Convert.ToDouble(textBox19.Text);
A.Values[3, 4] = Convert.ToDouble(textBox20.Text);
A.Values[4, 0] = Convert.ToDouble(textBox21.Text);
A.Values[4, 1] = Convert.ToDouble(textBox22.Text);
A.Values[4, 2] = Convert.ToDouble(textBox23.Text);
A.Values[4, 3] = Convert.ToDouble(textBox24.Text);
A.Values[4, 4] = Convert.ToDouble(textBox25.Text);
OOPTools_Math.Matrix Inver = new OOPTools_Math.Matrix(5, 5);
Inver = A.Invert(A);
public override string ToString()
{
double i = Inver.ToString();
return base.ToString();
}
MessageBox.Show(i);
}
答案 0 :(得分:-1)
您可以在inver类中覆盖ToString方法并提供自定义格式。然后你只需要在消息框显示中调用Inver的ToString
class Inver
{
...
public override string ToString()
{
//Build string representation of your inverse matrix
}
}
MessageBox.Show(inver.ToString()); // you can now simply do this