[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 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 ");
}
}
{
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 ");
}
}
本文转自 jirigala 51CTO博客,原文链接:http://blog.51cto.com/2347979/1196331,如需转载请自行联系原作者