|
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace ExtendedWebBrowser2
{
partial class OpenUrlForm : Form
{
public OpenUrlForm()
{
InitializeComponent();
}
private void okButton_Click(object sender, EventArgs e)
{
// Check if a valid URL was typed.
Uri result = null;
try
{
result = new Uri(this.addressTextBox.Text);
}
catch (UriFormatException)
{
// Eat this
}
if (result == null)
{
// Maybe the user forgot 'http://'
try
{
result = new Uri("http://" + this.addressTextBox.Text);
}
catch (UriFormatException)
{
// Eat this
}
if (result == null)
{
this.invalidAddressLabel.Visible = true;
return;
}
}
if (result.Scheme == "http" || result.Scheme == "https" || result.Scheme == "file")
{
// We got a valid address
_url = result;
DialogResult = DialogResult.OK;
Close();
}
else
{
// The URL might be valid, but the protocol is not supported
this.invalidAddressLabel.Visible = false;
return;
}
}
private Uri _url;
public Uri Url
{
get { return _url; }
}
private void OpenUrlForm_Load(object sender, EventArgs e)
{
this.invalidAddressLabel.Visible = false;
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
this.invalidAddressLabel.Visible = false;
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.
A list of licenses authors might use can be found here