请一些人帮助我的代码,我一次又一次地得到 ArguementOutofRange 异常。请告诉我我做错了什么。我为此尝试了每个循环,但它总是给出 ArgueOutofrange 错误。
例外是:-
“InvelidArguement = '3' 的值对 'SelectedIndex' 无效。参数名称:SelectedIndex”
&
警告是:
“异常的结果总是'true',因为'int'类型的值永远不会等于'int'类型的'null'?'”
这是我的代码:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
listBox1.Items.Add("www.google.com");
listBox1.Items.Add("www.facebook.com");
listBox1.Items.Add("www.yahoo.com");
listBox1.SelectedIndex = 0;
listBox1.DataSource = listBox1.Items;
}
private void button1_Click(object sender, EventArgs e)
{
var num = listBox1.Items.Count;
string str = Convert.ToString(num);
textBox1.Text = str;
for (int i = 0; i < num; )
{
webBrowser1.Navigate(listBox1.SelectedItem.ToString());
while (webBrowser1.ReadyState != WebBrowserReadyState.Complete)
{
Application.DoEvents();
if (webBrowser1.ReadyState == WebBrowserReadyState.Complete)
{
listBox1.SelectedIndex = listBox1.SelectedIndex + 1;
}
}
}
}
private void Form1_Load(object sender, EventArgs e)
{
var num = listBox1.Items.Count;
string str = Convert.ToString(num);
textBox1.Text = str;
}
}