c# 判断网络是连接到互联网

时间:2014-05-31 01:02:49   收藏:0   阅读:284


方法1:InternetGetConnectedState

        [System.Runtime.InteropServices.DllImport("wininet")]
        private extern static bool InternetGetConnectedState(out int connectionDescriptionint reservedValue);
       
        private void button1_Click(object senderEventArgs e)
        {
            int i = 0;
            if (InternetGetConnectedState(out i, 0))
                MessageBox.Show("联网状态");
            else
                MessageBox.Show("你网线掉了啦");
        }
http://www.cnblogs.com/hihell/archive/2011/09/20/2182626.html

修改下 
       [System.Runtime.InteropServices.DllImport("wininet")]
        private extern static bool InternetGetConnectedState(out int connectionDescriptionint reservedValue);
        //判断网络是连接到互联网
        public static bool IsNetWorkConnect()
        {
            int i = 0;
          return InternetGetConnectedState(out i, 0) ? true:false;
        }

          
            if ( IsNetWorkConnect() )
                MessageBox.Show("已连接到互联网");
            else
                MessageBox.Show("无网络")







来自为知笔记(Wiz)


c# 判断网络是连接到互联网,布布扣,bubuko.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!