c#使用实例之我的c#浏览器
来源:互联网 发布:r语言编程艺术 编辑:程序博客网 时间:2024/06/05 08:18
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;using System.Diagnostics;namespace WindowsFormsApplication1{ public partial class Form1 : Form { private string oldtitle; private Boolean isHasShow=false; public Form1() { InitializeComponent(); //窗体居中 //this.StartPosition = FormStartPosition.CenterScreen; this.Width = 1024; this.Height = 600; //调用Resources里面的国际化资源 this.Text = Properties.Resources.title; } private void button1_Click(object sender, EventArgs e) { webBrowser1.Navigate(textBox1.Text); // MessageBox.Show("ok"); } private void Form1_Shown(object sender, EventArgs e) { textBox1.Text = "http://www.baidu.com/"; webBrowser1.Navigate(textBox1.Text); isHasShow = true; Debug.WriteLine("浏览器版本:" + webBrowser1.Version.ToString()); this.Text = this.Text + ",浏览器版本:" + webBrowser1.Version.ToString(); this.oldtitle = this.Text; } private void textBox1_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { webBrowser1.Navigate(textBox1.Text); } } private void webBrowser1_NewWindow(object sender, CancelEventArgs e) { //禁止调用外部浏览器打开网页,使用本控件打开 try { string newurl = webBrowser1.Document.ActiveElement.GetAttribute("href"); if (!newurl.Contains("://")) { newurl = "http://" + newurl; } this.webBrowser1.Url = new System.Uri(newurl, System.UriKind.Absolute); e.Cancel = true; } catch (System.Exception ex) { } } private void webBrowser1_Navigating(object sender, WebBrowserNavigatingEventArgs e) { if (isHasShow) { //加载中 this.Text = this.oldtitle + ":正在加载中..."; } } private void webBrowser1_Navigated(object sender, WebBrowserNavigatedEventArgs e) { //在加载完成后,获取新打开窗体的url this.textBox1.Text = e.Url.ToString(); } private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) { if (isHasShow) { this.Text = this.oldtitle + ":加载完成..."; } //不用弹出新窗口 foreach (HtmlElement archor in this.webBrowser1.Document.Links) { archor.SetAttribute("target", "_self"); } } private void Form1_Load(object sender, EventArgs e) { //窗体居中 Rectangle rect=Screen.GetWorkingArea(this); Debug.WriteLine(rect.ToString()); this.Location = new Point((rect.Width - this.Width) / 2, (rect.Height - this.Height) / 2); } private void button1_MouseEnter(object sender, EventArgs e) { this.Cursor = Cursors.Hand; } private void 刷新ToolStripMenuItem1_Click(object sender, EventArgs e) { webBrowser1.Refresh(); } private void 上一页ToolStripMenuItem_Click(object sender, EventArgs e) { webBrowser1.GoForward(); } private void 后退一页ToolStripMenuItem1_Click(object sender, EventArgs e) { webBrowser1.GoBack(); } private void 主页ToolStripMenuItem_Click(object sender, EventArgs e) { webBrowser1.GoHome(); } private void button1_MouseLeave(object sender, EventArgs e) { this.Cursor = Cursors.Default; } }}
源码:http://pan.baidu.com/s/1i3gjvRf
0 0
- c#使用实例之我的c#浏览器
- c# delegate 的使用实例
- C#使用汇编的实例
- C# out的使用实例
- c#使用itextsharp的实例
- 我的记事本-C# RichTextBox实例
- 我的c#之路
- 我的C#之旅
- c#使用实例之简单的入门程序
- C#之实例化
- c# 反射使用实例
- c# 反射使用实例
- C#继承使用实例
- C# TASK 使用实例
- C#实例之随机数的猜想
- 编程实例 使用C#的BitmapData
- 编程实例 使用C#的BitmapData
- C#中正则表达式的使用实例
- 关于网狐棋牌6603源码的整理、编译和搭建
- 多个Fragment的Activity中上下文菜单的处理(ContextMenu)
- 第十二周项目2-OJ平台中多输入形式的处理2 分离正整数
- Binary Tree Zigzag Level Order Traversal
- Mapping Coordinates for Drawn Objects(为绘制对象映射坐标)
- c#使用实例之我的c#浏览器
- 中水处理设备:城市中水回用主要途径
- 关于for循环中break和return区别。
- Android编程获取手机型号,本机电话号码,sdk版本及firmware版本号(即系统版本号)
- SET QUOTED_IDENTIFIER OFF是什么意思
- 第十二周项目一阅读程序(5)
- cURL
- Android ActionBar完全解析,使用官方推荐的最佳导航栏(下)
- 《unix高级环境编程》进程间通信——消息队列