My code while making my personal Web browser
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Browser
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void GoButton_Click(object sender, EventArgs e)
{
if (String.IsNullOrEmpty(UrlTextBox.Text) ||
UrlTextBox.Text.Equals("about:blank"))
{
MessageBox.Show("Enter a valid URL.");
UrlTextBox.Focus();
return;
}
OpenURLInBrowser(UrlTextBox.Text);
}
private void OpenURLInBrowser(string url)
{
if (!url.StartsWith("http://") &&
!url.StartsWith("https://"))
{
url = "http://" + url;
}
try
{
webBrowser1.Navigate(new Uri(url));
}
catch (System.UriFormatException)
{
return;
}
}
private void HomeButton_Click(object sender, EventArgs e)
{
webBrowser1.GoHome();
}
private void BackButton_Click(object sender, EventArgs e)
{
if (webBrowser1.CanGoBack)
webBrowser1.GoBack();
}
private void NextButton_Click(object sender, EventArgs e)
{
if (webBrowser1.CanGoForward)
webBrowser1.GoForward();
}
private void RefreshButton_Click(object sender, EventArgs e)
{
webBrowser1.Refresh();
}
private void SaveButton_Click(object sender, EventArgs e)
{
webBrowser1.ShowSaveAsDialog();
}
private void PrintPreviewButton_Click(object sender, EventArgs e)
{
webBrowser1.ShowPrintPreviewDialog();
}
private void PrintButton_Click(object sender, EventArgs e)
{
webBrowser1.ShowPrintDialog();
}
private void PropertiesButton_Click(object sender, EventArgs e)
{
webBrowser1.ShowPropertiesDialog();
}
}
}
No comments:
Post a Comment