我正在创建一个网页重新加载程序,我试图从用户获取使用输入的重新加载数量,但是我无法获取用户输入的数量。Windows窗体:'输入字符串格式错误'错误
我试图获取用户输入的textBox2.Text
,但我有此错误:
input string was not in a currect format
此错误是在这一行kkk = System.Int32.Parse(textBox2.Text);
请帮我如何正确获取用户输入的值为int
。
这是我的程序代码:
public partial class Form1 : Form
{
public int kkk;
public Form1()
{
InitializeComponent();
}
private void progressBar1_Click(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
if (progressBar1.Value != kkk)
{
do
{
try
{
webBrowser1.Navigate(textBox1.Text);
while (webBrowser1.ReadyState != WebBrowserReadyState.Complete)
{
Application.DoEvents();
if(webBrowser1.ReadyState == WebBrowserReadyState.Complete)
{
progressBar1.Value = progressBar1.Value + 1;
}
}
MessageBox.Show("Loaded");
}
catch(Exception)
{
MessageBox.Show("failed");
}
}
while(progressBar1.Value !=kkk);
}
}
private void Form1_Load(object sender, EventArgs e)
{
kkk = System.Int32.Parse(textBox2.Text);
progressBar1.Maximum = kkk;
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
在表单加载事件中,您将textbox2的内容取出。文本并将其分配给kkk。但是那时textBox2里面什么都没有,所以它会抛出错误。 – JonH 2012-08-07 18:13:59