01-13-2011, 12:35 AM
(This post was last modified: 01-13-2011, 02:11 AM by nosferatus.)
Here is the code in C# (if anyone needs it)
Or you can use this :
Here is the upgraded source to vb 2008 in vb net and C#
Source in vb net & C#
Code:
using System;
using System.Net;
using System.Windows.Forms;
namespace WindowsApplication1
{
public partial class Form1
{
public Form1()
{
InitializeComponent();
//Added to support default instance behavour in C#
if (_defaultInstance == null)
_defaultInstance = this;
}
#region Default Instance
private static Form1 _defaultInstance;
/// <summary>
/// Added by the VB.Net to C# Converter to support default instance behavour in C#
/// </summary>
public static Form1 Default
{
get
{
if (_defaultInstance == null)
{
_defaultInstance = new Form1();
_defaultInstance.FormClosed += DefaultInstanceFormClosed;
}
return _defaultInstance;
}
}
private static void DefaultInstanceFormClosed(object sender, FormClosedEventArgs e)
{
_defaultInstance = null;
}
#endregion
public void Form1Load(Object sender, EventArgs e)
{
if (IsConnectionAvailibe())
//If there was internet on at the moment the application opened, add statements to enable the application for internet usage.
{
Label1.Visible = false;
TextBox2.Enabled = true;
TextBox1.Enabled = true;
Button1.Enabled = true;
Button2.Enabled = true;
Button3.Enabled = true;
}
else if (IsConnectionAvailibe() == false)
//If there wasn't internet when the application opened, add statements to disable internet using items to prevent errors.
{
Label1.Visible = true;
TextBox2.Enabled = false;
TextBox1.Enabled = false;
Button1.Enabled = false;
Button2.Enabled = false;
Button3.Enabled = false;
}
}
public bool IsConnectionAvailibe()
{
var objUrl = new Uri("http://www.google.com");
var objWebRequest = WebRequest.Create(objUrl);
WebResponse objResp;
try
{
objResp = objWebRequest.GetResponse();
if (objResp != null) objResp.Close();
return true;
}
catch (Exception)
{
return false;
}
}
}
}
Or you can use this :
Here is the upgraded source to vb 2008 in vb net and C#
Source in vb net & C#