【发布时间】:2012-08-04 19:20:01
【问题描述】:
我正在创建一个网页重新加载器,我正在尝试使用来自用户的输入来获取重新加载的数量,但我无法从用户那里获得输入的数量。
我正在尝试在 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 内没有任何内容,因此会引发错误。
标签: c# winforms input int user-input