




免费预览已结束,剩余14页可下载查看
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
网络程序设计课程设计报告专 业 网 络 工 程 学 号 09102428 姓 名 胡赛 2013 年 1 月 9 日 web浏览器设计1、 题目及要求(一)题目:web浏览器设计(2) 开发工具:,visual studio 2010(3) 运行环境:WindowsXP/7操作系统(4) 功能实现:1.有合理的首页页面设计,背景柔和2. 是利用C#编写程序,该浏览器简单但功能齐全3. 设计登陆页面1. 输入地址栏,支持所有的网址,并有转到功能2. 实现前进、后退、刷新等功能 3. 使用时同样可以最大化最小化4. 可以存储网址,进行网内连接5. 按钮是利用画图工具进行拷贝下来的6. 地址默认为百度7. 进度条的显示2、 系统概要设计(一)主要步骤 创建WebBrowser 首先使用Visual Studio 2010 Windows Forms应用程序,在这个程序中,给窗体(Form)添加一个ToolStrip和一个WebBrowser控件,在ToolStrip控件中,添加了一个Label,TextBox和一些Button控件。从工具箱拖动一个WebBrowser控件到Form上,根据Form的大小调整WebBrowser控件的大小和停靠位置,并将其停靠在底部。(二)主要函数:Navigate是WebBrowser中用来打开URL的一个方法。 webBrowser1.Navigate(new Uri(url))WebBrowser控件也内置了一些浏览器功能,如转到主页,前进,后退,刷新,保存,打印和其它功能,下面的代码片段显示了如何使用GoForeward,GoBack,GoHome和Refresh方法。3、 系统设计细节(一)浏览器主界面如图1-1图1-1浏览器主界面1. 输入地址栏,在ToolStrip中添加一个toolStripComboBox1用于输入地址以下代码用于转到地址栏中的地址private void toolStripButton3_Click(object sender, EventArgs e) if (String.IsNullOrEmpty(toolStripComboBox1.Text) /判断地址栏是否为空 MessageBox.Show(请输入有效地址); toolStripComboBox1.Focus(); return; OpenURL(toolStripComboBox1.Text); /把地址栏中的网址传到OpenURL方法中 /该方法用于根据传入的url,在webbrowser中显示 private void OpenURL(string url) if (!url.StartsWith(http:/) & !url.StartsWith(https:/) url = http:/ + url; try webBrowser1.Navigate(new Uri(url); toolStripComboBox1.Items.Add(url); catch (System.UriFormatException) return; 2.实现前进、后退、刷新等功能 private void toolStripButton1_Click(object sender, EventArgs e) if (webBrowser1.CanGoBack) webBrowser1.GoBack(); /后退 private void toolStripButton2_Click(object sender, EventArgs e) if(webBrowser1.CanGoForward) /前进 webBrowser1.GoForward(); private void toolStripButton4_Click(object sender, EventArgs e) webBrowser1.Refresh(); /刷新 private void toolStripButton5_Click(object sender, EventArgs e) webBrowser1.GoHome(); /主页(2) 可以存储网址,进行网内连接/在转到地址的同时把地址存储在文本文档中webBrowser1.Navigate(new Uri(url); toolStripComboBox1.Items.Add(url); saveURL(url);/把网址存到saveURL.Txt中 如图1-2private void saveURL(String url) FileStream fs = new FileStream(.saveURL.txt, FileMode.Append); StreamWriter sw = new StreamWriter(fs); sw.WriteLine(url); sw.Close();图1-2 本地文件/ 在构造方法中直接判断saveURL.txt中是否有地址,如果有,在运行程序之前把网址添加到ToolStripComboBox1中 如图1-3,1-4public Form1() InitializeComponent(); if (File.Exists(.saveURL.txt) StreamReader sr = new StreamReader(.saveURL.txt); string s = sr.ReadLine(); int i = 0; while (s != null & i+ 0) & (e.MaximumProgress 0) /已经加载数及正在加载数大于0时; toolStripProgressBar1.Maximum = Convert.ToInt32(e.MaximumProgress); /获取进度条最大值为下载文档字节总数 toolStripProgressBar1.Step = Convert.ToInt32(e.CurrentProgress); /获取已经下载字节数 toolStripProgressBar1.PerformStep(); /增加到当前位置 else if (webBrowser1.ReadyState = WebBrowserReadyState.Complete) /下载完成 toolStripProgressBar1.Value = 0; /进度条设为0 toolStripProgressBar1.Visible = false; /不显示进度条 图1-6进度条4、 课程设计总结本次课程设计我选的题目是Web浏览器设计,使用的语言是C#。在刚开始做的时候有挺多问题不懂的,但是通过去图书馆、上网查找相关资料、询问同学等方法使得问题得以解决,比如前进、后退、刷新等按钮的添加,网址的保存等,让我充分认识到C#语言功能的强大。最终程序完成了,虽然浏览器只是简单版的,仅含有一些基本功能,但是在做的过程中一边做,一边学是我的理论知识得以丰富同时锻炼了我的动手能力。本次的课程设计令我学到了很多,使我对C#这门编程语言更熟悉了,同时在课程设计的过程中,碰到问题积极查找资料、和同学交流讨论也让我收获良多。参考文献:1黄永兵. Visual Studio 2010构建Web浏览器应用程序. 51技术频道. 2011: 01-24.2王超、潘阳. Visual C#通用范例开发经典M北京电子工业出版社2008:54-101附录程序代码Form1.csusing 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.Runtime.InteropServices;using System.IO;namespace _09102428husai public partial class Form1 : Form public Form1() InitializeComponent(); if (File.Exists(.saveURL.txt) StreamReader sr = new StreamReader(.saveURL.txt); string s = sr.ReadLine(); int i = 0; while (s != null & i+ 0) & (e.MaximumProgress 0) toolStripProgressBar1.Maximum = Convert.ToInt32(e.MaximumProgress); toolStripProgressBar1.Step = Convert.ToInt32(e.CurrentProgress); toolStripProgressBar1.PerformStep(); else if (webBrowser1.ReadyState = WebBrowserReadyState.Complete) toolStripProgressBar1.Value = 0; toolStripProgressBar1.Visible = false; private void toolStripButton3_Click(object sender, EventArgs e) if (String.IsNullOrEmpty(ToolStripComboBox1.Text) MessageBox.Show(请输入有效地址!); ToolStripComboBox1.Focus(); return; OpenURL(ToolStripComboBox1.Text); private void OpenURL(string url) if (!url.StartsWith(http:/) & !url.StartsWith(https:/) url = http:/ + url; try webBrowser1.Navigate(new Uri(url); ToolStripComboBox1.Items.Add(url); saveURL(url); catch (System.UriFormatException) return; private void saveURL(String url) FileStream fs = new FileStream(.saveURL.txt, FileMode.Append); StreamWriter sw = new StreamWriter(fs); sw.WriteLine(url); sw.Close(); private void toolStripButton1_Click(object sender, EventArgs e) if (webBrowser1.CanGoBack) webBrowser1.GoBack(); private void toolStripButton2_Click(object sender, EventArgs e) if(webBrowser1.CanGoForward) webBrowser1.GoForward(); private void toolStripButton4_Click(object sender, EventArgs e) webBrowser1.Refresh(); private void toolStripButton5_Click(object sender, EventArgs e) webBrowser1.GoHome(); private void ToolStripComboBox1_Click(object sender, EventArgs e) private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) Form1.Designer.csnamespace _09102428husai partial class Form1 / / 必需的设计器变量。 / private System.ComponentModel.IContainer components = null; / / 清理所有正在使用的资源。 / / 如果应释放托管资源,为 true;否则为 false。 protected override void Dispose(bool disposing) if (disposing & (components != null) components.Dispose(); base.Dispose(disposing); #region Windows 窗体设计器生成的代码 / / 设计器支持所需的方法 - 不要 / 使用代码编辑器修改此方法的内容。 / private void InitializeComponent() System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1); this.toolStrip1 = new System.Windows.Forms.ToolStrip(); this.toolStripButton1 = new System.Windows.Forms.ToolStripButton(); this.toolStripButton2 = new System.Windows.Forms.ToolStripButton(); this.ToolStripComboBox1 = new System.Windows.Forms.ToolStripComboBox(); this.toolStripButton3 = new System.Windows.Forms.ToolStripButton(); this.toolStripButton4 = new System.Windows.Forms.ToolStripButton(); this.toolStripButton5 = new System.Windows.Forms.ToolStripButton(); this.webBrowser1 = new System.Windows.Forms.WebBrowser(); this.toolStrip2 = new System.Windows.Forms.ToolStrip(); this.toolStripProgressBar1 = new System.Windows.Forms.ToolStripProgressBar(); this.toolStrip1.SuspendLayout(); this.toolStrip2.SuspendLayout(); this.SuspendLayout(); / / toolStrip1 / this.toolStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem this.toolStripButton1, this.toolStripButton2, this.ToolStripComboBox1, this.toolStripButton3, this.toolStripButton4, this.toolStripButton5); this.toolStrip1.Location = new System.Drawing.Point(0, 0); this.toolStrip1.Name = toolStrip1; this.toolStrip1.Size = new System.Drawing.Size(631, 25); this.toolStrip1.TabIndex = 0; this.toolStrip1.Text = toolStrip1; / / toolStripButton1 / this.toolStripButton1.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image; this.toolStripButton1.Image = (System.Drawing.Image)(resources.GetObject(toolStripButton1.Image); this.toolStripButton1.ImageTransparentColor = System.Drawing.Color.Magenta; this.toolStripButton1.Name = toolStripButton1; this.toolStripButton1.Size = new System.Drawing.Size(23, 22); this.toolStripButton1.Text = toolStripButton1; this.toolStripButton1.Click += new System.EventHandler(this.toolStripButton1_Click); / / toolStripButton2 / this.toolStripButton2.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image; this.toolStripButton2.Image = (System.Drawing.Image)(resources.GetObject(toolStripButton2.Image); this.toolStripButton2.ImageTransparentColor = System.Drawing.Color.Magenta; this.toolStripButton2.Name = toolStripButton2; this.toolStripButton2.Size = new System.Drawing.Size(23, 22); this.toolStripButton2.Text = toolStripButton2; this.toolStripButton2.Click += new System.EventHandler(this.toolStripButton2_Click); / / ToolStripComboBox1 / this.ToolStripComboBox1.Name = ToolStripComboBox1; this.ToolStripComboBox1.Size = new System.Drawing.Size(300, 25); this.ToolStripComboBox1.Click += new System.EventHandler(this.ToolStripComboBox1_Click); / / toolStripButton3 / this.toolStripButton3.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image; this.toolStripButton3.Image = (System.Drawing.Image)(resources.GetObject(toolStripButton3.Image); this.toolStripButton3.ImageTransparentColor = System.Drawing.Color.Magenta; this.toolStripButton3.Name = toolStripButton3; this.toolStripButton3.Size = new System.Drawing.Size(23, 22); this.toolStripButton3.Text = toolStripButton3; this.toolStripButton3.Click += new System.EventHandler(this.toolStripButton3_Click); / / toolStripButton4 / this.toolStripButton4.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image; this.toolStripButton4.Image = (System.Drawing.Image)(resources.GetObject(toolStripButton4.Image); this.toolStripButton4.ImageTransparentColor = System.Drawing.Color.Magenta; this.toolStripButton4.Name = toolStripButton4; this.toolStripButton4.Size = new System.Drawing.Size(23, 22); this.toolStripButton4.Text = toolStripButton4; this.toolStripButton4.Click += new System.EventHandler(this.toolStripButton4_Click); / / toolStripButton5 / this.toolStripButton5.Alignment = System.Windows.Forms.ToolStripItemAlignment.Right; this.toolStripButton5.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image; this.toolStripButton5.Image = (System.Drawing.Image)(resources.GetObject(toolStripButton5.Image); this.toolStripButton5.ImageTransparentColor = System.Drawing.Color.Magenta; this.toolStripButton5.Name = toolStripButton5; this.toolStripButton5.Size = new System.Drawing.Size(23, 22); this.toolStripButton5.Text = toolStripButton5; this.toolStripButton5.Click += new System.EventHandler(this.toolStripButton5_Click); / / webBrowser1 / this.webBrowser1.Dock = System.Windows.Forms.DockStyle.Fill; this.webBrowser1.Location = new System.Drawing.Point(0, 25); this.webBrowser1.MinimumSize = new System.Drawing.Size(20, 20); this.webBrowser1.Name = webBrowser1; this.webBrowser1.Size = new System.Drawing.Size(631, 433); this.webBrowser1.TabIndex = 1; this.webBrowser1.Url = new System.Uri(, System.UriKind.Absolute); this.webBrowser1.DocumentCompleted += new System.Windows.Forms.WebBrowserDocumentCompletedEventHandler(this.webBrowser1_DocumentCompleted); / / toolStrip2 / this.toolStrip2.Dock = System.Windows.Forms.DockStyle.Bottom; this.toolStrip2.Items.AddRange(new System.Windows.Forms.ToolStripItem this.toolStripProgressBar1); this.toolStrip2.Location = new System.Drawing.Point(0, 433); this.toolStrip2.Name = toolStrip2; this.toolStrip2.Size = new System.Drawing.Size(631, 25); this.toolStrip2.TabIndex = 2; this.toolStrip2.Text = toolStrip2; / / toolStripProgressBar1 / this.toolStripProgressBar1.Name = toolStripProgressBar1; this.toolStripProgressBar1.Size = new System.Drawing.Si
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 系统集成方案-洞察及研究
- 异构计算融合-洞察及研究
- 2026届四川省眉山市车城中学高三语文第一学期期末质量跟踪监视试题
- 土地承包合同终止与生态修复责任书
- 钟竹离婚协议:财产分割子女抚养权具体执行书
- 2025年安徽省农垦集团有限公司所属企业招聘笔试备考及答案详解(有一套)
- 2025年肝脏胆道外科手术技能操作评估试卷答案及解析
- 供应链风险管理在港口物流中的应用研究报告
- 2025年神经内科常见疾病诊疗方案策划模拟考试卷答案及解析
- 农业信息技术与智能设备应用合作协议
- 药学三基考试试题(带答案)
- 心衰中医护理课件
- 婴幼儿的保育与教育 课件 第七章 婴幼儿语言发展与教育
- 2025广西公需科目真题续集(附答案)
- 医德医风培训课件内容
- 挖孔桩孔内气体检测
- 古诗活动沙龙活动方案
- 《大学生创新创业基础》教案 第1课 大学生创新创业教育概论一
- CJ/T 120-2016给水涂塑复合钢管
- T/CECS 10214-2022钢面镁质复合风管
- (高清版)DG∕TJ 08-202-2020 钻孔灌注桩施工标准
评论
0/150
提交评论