111,092
社区成员




//导入dll
[DllImport("wininet.dll", EntryPoint = "InternetGetConnectedState")]
//判断网络状况的方法,返回值true为连接,false为未连接
public extern static bool InternetGetConnectedState(out int conState, int reder);
//在你的button事件中写下如下代码就行
private void btnNetStatus_Click(object sender, EventArgs e)
{
int n =0;
if (InternetGetConnectedState(out n,0))
{
MessageBox.Show("网终处于连接状态");
}
else
{
MessageBox.Show("网络处于未连接状态");
}
}