[System.Runtime.InteropServices.DllImport("wininet.dll")]
private extern static bool InternetGetConnectedState(out int Description, int ReservedValue);
public static bool IsConnectedToInternet()
{
int Desc = 0;
return InternetGetConnectedState(out Desc, 0);
}
private void button1_Click(object sender, EventArgs e)
{
if (Form1.IsConnectedToInternet())
MessageBox.Show("OK");
else
MessageBox.Show("No");
}