复制代码
        [DllImport("wininet.dll")]
        private extern static bool InternetGetConnectedState(out int conn, int val);

        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            int Out;
            if (InternetGetConnectedState(out Out, 0) == true)
            {
                MessageBox.Show("Connected !");
            }
            else
            {
                MessageBox.Show("Not Connected !");
            }
        }
复制代码

 

判断邮箱地址是否有效的参考代码

复制代码
        private void button1_Click(object sender, EventArgs e)
        {
            string pattern = null;
            pattern = "^([0-9a-zA-Z]([-\\.\\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\\w]*[0-9a-zA-Z]\\.)+[a-zA-Z]{2,9})$";

            if (Regex.IsMatch("feedback@net-informations.com", pattern))
            {
                MessageBox.Show ("Valid Email address ");
            }
            else
            {
                MessageBox.Show("Not a valid Email address ");
            }
        }
复制代码
 posted on 2012-05-11 10:49  纳米程序员  阅读(986)  评论(0编辑  收藏  举报