c#判断网络连接状态的示例分享
程序员文章站
2023-12-20 15:58:40
复制代码 代码如下:public partial class form1 : form {
[dllimport("wininet.dll")]
privat...
复制代码 代码如下:
public partial class form1 : form {
[dllimport("wininet.dll")]
private extern static bool getinterstate(out int conn, int val);
public form1() {
initializecomponent();
getnet();
}
//判断当前是否连接入internet网络
private void getnet()
{
int out;
if (getinterstate(out out, 0) == true)
{
label1.text = " 网络已连接!";
}else{
label1.text = " 网络未成功连接!";
}
}
}