代碼如下:
view plaincopy to clipboardprint?[DllImport("wininet.dll")]
[DllImport("wininet.dll")]view plaincopy to clipboardprint? private extern static bool InternetGetConnectedState(int Description, int ReservedValue);
public static bool IsConnectedToInternet()
{
int Desc = 0;
return InternetGetConnectedState(Desc, 0);
}
private void button1_Click(object sender, EventArgs e)
{
//檢測網絡狀態
if (!IsConnectedToInternet())
{
MessageBox.Show("當前不能連接到服務器,請檢查網絡、防火牆等設備!");
return;
}
}
作者“靈雨飄零的專欄”