我正在尝试使用列表框浏览网页,我已经添加了三个链接。所有三个链接都加载良好,但是当第三个链接完成加载时,我得到了这个异常。
例外是:
InvelidArguement = value of '3' is not valid for 'SelectedIndex'. Parameter name:
SelectedIndex
警告是:
`The result of the exception is always 'true' since a value of type 'int' is
never equal to 'null' of type 'int?'
这是我的程序图像:
这是我的程序代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
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 listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
do
{
webBrowser1.Navigate(listBox1.SelectedItem.ToString());
while (webBrowser1.ReadyState != WebBrowserReadyState.Complete)
{
Application.DoEvents();
if(webBrowser1.ReadyState == WebBrowserReadyState.Complete)
{
listBox1.SelectedIndex = listBox1.SelectedIndex+1;
}
}
} while (listBox1.SelectedIndex != null);
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}