public partial class ConnectQualityView
{
#region "Declarations"
string ConnectionQualityString = "Off";
[DllImport("wininet.dll", ExactSpelling=true, CharSet=CharSet.Ansi, SetLastError=true)]
private static extern bool InternetGetConnectedState(ref int lpSFlags, int dwReserved);
public enum InetConnState
{
modem = 0x1,
lan = 0x2,
proxy = 0x4,
ras = 0x10,
offline = 0x20,
configured = 0x40
}
#endregion
#region "Control Methods"
private void ConnectQualityView_Load(object sender, System.EventArgs e)
{
Timer1.Enabled = true;
this.DoubleBuffered = true;
}
private void Timer1_Tick(System.Object sender, System.EventArgs e)
{
lblConnectStatus.Refresh();
bool blnState;
blnState = CheckInetConnection();
}
public bool CheckInetConnection()
{
long lngFlags;
int temp_int = (int) lngFlags;
if (InternetGetConnectedState(ref temp_int, 0))
{
// True
if (System.Convert.ToBoolean(lngFlags) && System.Convert.ToBoolean(InetConnState.lan))
{
switch (ConnectionQualityString)
{
case "Good":
lblConnectStatus.ForeColor = Color.Green;
lblConnectStatus.Text = "Connection Quality: Good";
ConnectionQualityString = "Good";
break;
case "Intermittent":
lblConnectStatus.ForeColor = Color.Green;
lblConnectStatus.Text = "Connection Quality: Good";
ConnectionQualityString = "Good";
break;
case "Off":
lblConnectStatus.ForeColor = Color.DarkOrange;
lblConnectStatus.Text = "Connection Quality: Intermittent";
ConnectionQualityString = "Intermittent";
break;
}
this.Refresh();
}
else if (System.Convert.ToInt64(System.Convert.ToBoolean(lngFlags )) & (long)
InetConnState.modem)
{
switch (ConnectionQualityString)
{
case "Good":
lblConnectStatus.ForeColor = Color.Green;
lblConnectStatus.Text = "Connection Quality: Good";
ConnectionQualityString = "Good";
break;
case "Intermittent":
lblConnectStatus.ForeColor = Color.Green;
lblConnectStatus.Text = "Connection Quality: Good";
ConnectionQualityString = "Good";
break;
case "Off":
lblConnectStatus.ForeColor = Color.DarkOrange;
lblConnectStatus.Text = "Connection Quality: Intermittent";
ConnectionQualityString = "Intermittent";
break;
}
}
else if (System.Convert.ToInt64(System.Convert.ToBoolean(lngFlags )) & (long)
InetConnState.configured)
{
switch (ConnectionQualityString)
{
case "Good":
lblConnectStatus.ForeColor = Color.Green;
lblConnectStatus.Text = "Connection Quality: Good";
ConnectionQualityString = "Good";
break;
case "Intermittent":
lblConnectStatus.ForeColor = Color.Green;
lblConnectStatus.Text = "Connection Quality: Good";
ConnectionQualityString = "Good";
break;
case "Off":
lblConnectStatus.ForeColor = Color.DarkOrange;
lblConnectStatus.Text = "Connection Quality: Intermittent";
ConnectionQualityString = "Intermittent";
break;
}
}
else if (System.Convert.ToInt64(System.Convert.ToBoolean(lngFlags )) & (long) InetConnState.proxy)
{
switch (ConnectionQualityString)
{
case "Good":
lblConnectStatus.ForeColor = Color.Green;
lblConnectStatus.Text = "Connection Quality: Good";
ConnectionQualityString = "Good";
break;
case "Intermittent":
lblConnectStatus.ForeColor = Color.Green;
lblConnectStatus.Text = "Connection Quality: Good";
ConnectionQualityString = "Good";
break;
case "Off":
lblConnectStatus.ForeColor = Color.DarkOrange;
lblConnectStatus.Text = "Connection Quality: Intermittent";
ConnectionQualityString = "Intermittent";
break;
}
}
else if (System.Convert.ToInt64(System.Convert.ToBoolean(lngFlags)) & (long) InetConnState.ras)
{
switch (ConnectionQualityString)
{
case "Good":
lblConnectStatus.ForeColor = Color.Green;
lblConnectStatus.Text = "Connection Quality: Good";
ConnectionQualityString = "Good";
break;
case "Intermittent":
lblConnectStatus.ForeColor = Color.Green;
lblConnectStatus.Text = "Connection Quality: Good";
ConnectionQualityString = "Good";
break;
case "Off":
lblConnectStatus.ForeColor = Color.DarkOrange;
lblConnectStatus.Text = "Connection Quality: Intermittent";
ConnectionQualityString = "Intermittent";
break;
}
}
else if (System.Convert.ToInt64(System.Convert.ToBoolean(lngFlags )) & (long) InetConnState.offline)
{
switch (ConnectionQualityString)
{
case "Good":
lblConnectStatus.ForeColor = Color.Green;
lblConnectStatus.Text = "Connection Quality: Good";
ConnectionQualityString = "Good";
break;
case "Intermittent":
lblConnectStatus.ForeColor = Color.Green;
lblConnectStatus.Text = "Connection Quality: Good";
ConnectionQualityString = "Good";
break;
case "Off":
lblConnectStatus.ForeColor = Color.DarkOrange;
lblConnectStatus.Text = "Connection Quality: Intermittent";
ConnectionQualityString = "Intermittent";
break;
}
}
}
else
{
// False
switch (ConnectionQualityString)
{
case "Good":
lblConnectStatus.ForeColor = Color.DarkOrange;
lblConnectStatus.Text = "Connection Quality: Intermittent";
ConnectionQualityString = "Intermittent";
break;
case "Intermittent":
lblConnectStatus.ForeColor = Color.Red;
lblConnectStatus.Text = "Connection Quality: Off";
ConnectionQualityString = "Off";
break;
case "Off":
lblConnectStatus.ForeColor = Color.Red;
lblConnectStatus.Text = "Connection Quality: Off";
ConnectionQualityString = "Off";
break;
}
}
}
#endregion
}