C# 金刚网页浏览器

发布时间:2009年06月04日      浏览次数:453 次
最近看了<<C#2005实例>>就想就书上的代码做一个网页浏览器来就,感觉还不错就发到网上来和大家一起分享.下载是我做的截图:
就只有一个FORM
下面是源码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace JinGangInternet
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
Navigate(this.textBox1.Text);
}

private void 后退ToolStripMenuItem_Click(object sender, EventArgs e)
{
webBrowser1.GoBack();
}

private void 前进ToolStripMenuItem_Click(object sender, EventArgs e)
{
this.webBrowser1.GoForward();
}

private void 停止ToolStripMenuItem_Click(object sender, EventArgs e)
{
webBrowser1.Stop();
}

private void 刷新ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (!webBrowser1.Url.Equals("about:blank"))
{
webBrowser1.Refresh();
}
}

private void 主页ToolStripMenuItem_Click(object sender, EventArgs e)
{
webBrowser1.GoHome();
}

private void 保存ToolStripMenuItem_Click(object sender, EventArgs e)
{
webBrowser1.ShowSaveAsDialog();
}

private void 打印ToolStripMenuItem_Click(object sender, EventArgs e)
{
webBrowser1.ShowPrintDialog();
}

private void 属性ToolStripMenuItem_Click(object sender, EventArgs e)
{
webBrowser1.ShowPropertiesDialog();
}
//设置后退按钮状态
private void webBrowser1_CanGoBackChanged(object sender, EventArgs e)
{
this.后退ToolStripMenuItem.Enabled = webBrowser1.CanGoBack;
}
//设置前进按钮状态
private void webBrowser1_CanGoForwardChanged(object sender, EventArgs e)
{
this.前进ToolStripMenuItem.Enabled = webBrowser1.CanGoForward;
}
//设置网页标题
private void webBrowser1_DocumentTitleChanged(object sender, EventArgs e)
{
this.Text = webBrowser1.DocumentTitle;
}
//显示网址
private void webBrowser1_Navigated(object sender, WebBrowserNavigatedEventArgs e)
{
this.textBox1.Text = webBrowser1.Url.ToString();
}
//浏览网页
private void Navigate(String address)
{
if (String.IsNullOrEmpty(address)) return;
if (address.Equals("about:blank")) return;
if (!address.StartsWith("http://")) address = "http://" + address;
try
{
webBrowser1.Navigate(new Uri(address));
}
catch (System.UriFormatException)
{
return;
}
}

private void Form1_Load(object sender, EventArgs e)
{
webBrowser1.CanGoBackChanged += new EventHandler(webBrowser1_CanGoBackChanged);
webBrowser1.CanGoForwardChanged += new EventHandler(webBrowser1_CanGoForwardChanged);
webBrowser1.DocumentTitleChanged += new EventHandler(webBrowser1_DocumentTitleChanged);
this.webBrowser1.Navigated += new WebBrowserNavigatedEventHandler(this.webBrowser1_Navigated);
}
}
}
源码下载地址:
http://dl2.csdn.net/down4/20070913/13232542257.rar
免责声明:本站相关技术文章信息部分来自网络,目的主要是传播更多信息,如果您认为本站的某些信息侵犯了您的版权,请与我们联系,我们会即时妥善的处理,谢谢合作!