求大神啊!!!C#出现了targetInvocationException的问题
他说我出现了那个问题,发现错在那个输入赋值的地方,也就是timer控件里面的东西,怎么样才能解决?有些代码我删除了,因为太多放不下。
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
const double pi = 3.141592654;
double δ0, δ1, δ2, δ3;
double r0, r1, w, h, e0;
double[] sva = new double[3];
int i, angle;
int x1, y1;
//初始值
private void button2_Click(object sender, EventArgs e)
{
comboBox1.Text = "(1)偏置(或对心)尖顶推杆盘形凸轮";
comboBox2.Text = "(2)二次多项式";
comboBox3.Text = "(3)五次多项式";
textBox1.Text = "30";
textBox2.Text = "0";
textBox3.Text = "0.5";
textBox4.Text = "10";
textBox5.Text = "90";
textBox6.Text = "90";
textBox7.Text = "90";
textBox8.Text = "90";
textBox13.Text = "7";
}
//start
private void button3_Click(object sender, EventArgs e)
{
timer1.Interval = 500;
timer1.Enabled = true;
}
//pause
private void button4_Click(object sender, EventArgs e)
{
timer1.Enabled = false;
}
//改用数据前请先清零
private void button5_Click(object sender, EventArgs e)
{
Graphics g1 = this.pictureBox1.CreateGraphics();
Graphics g2 = this.pictureBox2.CreateGraphics();
Graphics g3 = this.pictureBox3.CreateGraphics();
Graphics g4 = this.pictureBox4.CreateGraphics();
Graphics g5 = this.pictureBox5.CreateGraphics();
g1.Clear(this.BackColor);
g2.Clear(this.BackColor);
g3.Clear(this.BackColor);
g4.Clear(this.BackColor);
g5.Clear(this.BackColor);
timer1.Enabled = false;
textBox1.Text = "";
textBox2.Text = "";
textBox3.Text = "";
textBox4.Text = "";
textBox5.Text = "";
textBox6.Text = "";
textBox7.Text = "";
textBox8.Text = "";
textBox9.Text = "";
textBox10.Text = "";
textBox11.Text = "";
textBox12.Text = "";
textBox13.Text = "";
comboBox1.Text = "";
comboBox2.Text = "";
comboBox3.Text = "";
angle = 0;
i = 0;
}
//timer控件
private void timer1_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
r0 = Double.Parse(textBox1.Text);
r1 = Double.Parse(textBox2.Text);
w = Double.Parse(textBox3.Text);
h = Double.Parse(textBox4.Text);
δ0 = Double.Parse(textBox5.Text); δ0 = δ0 * pi / 180;
δ1 = Double.Parse(textBox6.Text); δ1 = δ1 * pi / 180;
δ2 = Double.Parse(textBox7.Text); δ2 = δ2 * pi / 180;
δ3 = Double.Parse(textBox8.Text); δ3 = δ3 * pi / 180;
e0 = Double.Parse(textBox13.Text);
}
}
c# textbox
[解决办法]
你的TextBox值无法转换成double
[解决办法]
TextBox值转换没问题,你设断点调试一下
[解决办法]
空字符串不能转化为double
[解决办法]
应该是你textBox1.Text出现空值了