资源描述
C#程序设计
设计阐明书
简易IE浏览器设计与实现
学 生 姓 名:郭成成
学 号:
班 级:计 算 机 (一) 班
专 业:计算机应用技术
指 导 教 师:胡教师
课程设计任务书
— 年第二学期
课 程设计名 称:C#课程设计 设 计 题 目:简易IE浏览器设计与实现 完 成 期 限:自 年 11 月 8 日至 年 11 月 29 日共 3 周
设计根据、规定及重要内容:
依照程序设计所学知识,设计与实现一种简朴浏览器,该简朴浏览器设计内容和功能规定如下:
(1) 有合理首页页面设计,背景柔和。
(2) 有各种按钮,例如说迈进、后退、刷新删除等 。
(3) 输入地址栏,支持所有网址,并有转到功能 。
(4)设计登陆页面。
(5) 可以存储网址,进行网内连接。
(6)是运用 C#编写程序,该浏览器简朴但功能齐全 。
(7) 使用时同样可以最大化最小化 。
(8)按钮是运用画图工具进行拷贝下来 。
(9) 地址默以为百度 。
规定:系统功能设计基本完善,并写出详细设计阐明书。
摘 要
核心词: 核心词:迈进、后退、刷新、输入合法地址、运营程序,在网内搜索,使用 vs 中 C#编写程序,利 用画图工具。拷贝迈进、后退按钮。
1 课题描述
运用C#编写简朴程序,创立一种简易IE浏览器,包括基本功能,培养编写程序兴趣。 实践中理解浏览器某些特性
2 程序设计流程图
2.1 系统阐明
使用 win7 系统,vs 中控制台应用程序,设计主界面,并拖放按钮。 具备普通浏览器基本功能,迈进、后退、刷新、地址等。在输入地址栏。设默认地址为 百度,便于使用,刷新功能,在网速不是太好,有一点卡时,刷新一下,主界面可以最大 化和最小化。使用绿色为边框颜色,用画图工具拷贝文献按钮,设有六个小按钮,涉及前 进、后退、删除、刷新、转到等按钮。
2.1 主界面设计主界面用纯白色背景,界面以中档大小为宜。 使用绿色为边框颜色,用画图工具拷贝文献 按钮,设有六个小按钮,涉及迈进、后退、删除、刷新、转到等按钮。主界面用纯白色背 景,界面以中档大小为宜。
3 功能设计
3.1 主界面功能设计
主界面功能设计主界面打开时,显示空白背景。地址为默认百度
3.2 后退功能设计
后退功能设计当打开网页时,想浏览之前网页,不需要重新打开,只需按倒退按钮,就可以浏览之前 网页,这是退后按钮功能
3.3 浏览功能设计
浏览功能设计浏览基本网页视频、文本文献等,浏览新闻杂志,打开别网页
4 测试
4.1 系统测试
4.2 调试成果
4.3 错误因素分析:无
总结
通过这次课程设计,我理解了简朴浏览器编译,收获很大,在教师指引下,认真修改 自己写程序,从而更加理解了 C#使用,但愿自己可以在后来更加努力学习,非常感 谢学校开设这一课程,让我收获很大。
参照文献
[1] 崔淼、陈明非.Visual C# 程序设计教程,
[2] 马靖善等.C 语言程序设计.清华大学出版社,
[3] 谭浩强.C 语言程序设计(第二版).北京:高等教诲出版社,
[4] 黄超.C 语言程序设计.北京.人民邮电出版社.
[5] 谭浩强等.C 语言程序设计.清华大学出版社,
[6]方敏、张彤.C 语言程序设计.西安电子科技大学出版社.
附录:
源代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace MyIEr
{ public partial class frmIE :Form
{ public frmIE()
{ InitializeComponent();
InitializeOpenFileDialog();}
private string formatPath(string myPath)
{ string trimmed = myPath.Trim();
if (trimmed.StartsWith("file:"))
{ trimmed = trimmed.Replace(@"file:///","");
trimmed = trimmed.Replace("file://","\\");
trimmed = trimmed.Replace("/",@"\");}
return trimmed;}
private bool canGoUp(string myPath)
{ myPath = myPath.TrimStart(@"\".ToCharArray());
myPath += @"\";
return (!(myPath.IndexOf(@"\") == myPath.LastIndexOf(@"\")) && !((myPath.IndexOf(@"\") + 1) == myPath.LastIndexOf(@"\")));}
private void NavigateToURL()
{ try
{ //调用Navigate办法
this.webBrowser1.Navigate(formatPath(this.urlTextBox.Text));}
catch
{ MessageBox.Show("无效URL。",
this.Text,MessageBoxButtons.OK,
MessageBoxIcon.Error);} }
private void UpdateButtons()
{ //更新【后退】与【迈进】按钮
this.btnBack.Enabled = this.webBrowser1.CanGoBack;
this.btnForward.Enabled = this.webBrowser1.CanGoForward;}
private void InitializeOpenFileDialog()
{ //设定“打开文献”对话框初始目录
openFileDialog1.InitialDirectory = Environment.CurrentDirectory + @"\HTML";
//设定文献名筛选字符串以以便选用特定格式文献
openFileDialog1.Filter =
"网页(*.HTM;*.HTML)|*.HTM;*.HTML|XML 文献(*.XML)|*.XML|Flash 文献(*.SWF)|*.SWF|Office 文献(*.DOC;*.XLS;*.PPT)|*.DOC;*.XLS;*.PPT";
//设定“打开文献”对话框标题
openFileDialog1.Title = "请选取特定格式文献";
//设定“打开文献”对话框在关闭前还原当前目录
openFileDialog1.RestoreDirectory = true;}
private void btnBack_ButtonClick(object sender,EventArgs e)
{this.webBrowser1.GoBack();}
private void btnForward_ButtonClick(object sender,EventArgs e)
{this.webBrowser1.GoForward();}
private void btnStop_Click(object sender,EventArgs e)
{this.webBrowser1.Stop();}
private void btnRefresh_Click(object sender,EventArgs e)
{this.webBrowser1.Refresh();}
private void btnHome_Click(object sender,EventArgs e)
{this.webBrowser1.GoHome();}
private void tbnSearch_Click(object sender,EventArgs e)
{this.webBrowser1.GoSearch();}
private void btnGo_Click(object sender,EventArgs e)
{this.NavigateToURL();}
private void btnPrint_Click(object sender,EventArgs e)
{this.webBrowser1.Print();}
private void btnUplevel_Click(object sender,EventArgs e)
{string myPath = formatPath(this.webBrowser1.Url.ToString());
if (canGoUp(myPath))
{myPath = myPath.Substring(0,myPath.LastIndexOf(@"\"));
try
{this.webBrowser1.Navigate(myPath);}
catch
{btnUplevel.Enabled = false;} } }
private void urlTextBox_KeyDown(object sender,KeyEventArgs e)
{ //按下Enter键便会进入所输入URL
if (e.KeyCode == Keys.Enter)
{this.NavigateToURL();} }
private void webBrowser1_Navigating(object sender,WebBrowserNavigatingEventArgs e)
{ //更新【后退】与【迈进】按钮
UpdateButtons();
this.tsWebProgressBar.Visible = true;}
private void webBrowser1_Navigated(object sender,WebBrowserNavigatedEventArgs e)
{ //更新【后退】与【迈进】按钮
UpdateButtons();
//更新URL文本框
this.urlTextBox.Text = this.webBrowser1.Url.ToString();
//更新文字
this.statusText.Text = "正在打开网页" + this.webBrowser1.Url.ToString();}
private void webBrowser1_DocumentCompleted(object sender,WebBrowserDocumentCompletedEventArgs e)
{ this.statusText.Text = "完毕";
this.btnUplevel.Enabled = canGoUp(formatPath(this.urlTextBox.Text));
this.tsWebProgressBar.Visible = false;
this.tsWebProgressBar.Value = 0;}
private void webBrowser1_ProgressChanged(object sender,WebBrowserProgressChangedEventArgs e)
{ this.tsWebProgressBar.Value = (int)(((float)e.CurrentProgress /
(float)e.MaximumProgress)
* 100);}
private void ViewSourceMenuItem_Click(object sender,EventArgs e)
{ //依照网址来确认文献名称
string myUrl = this.webBrowser1.Url.ToString();
string myFileName = "";
if (myUrl.ToString().StartsWith("http") || Path.GetExtension(myUrl).StartsWith(".htm"))
{string myAbsolutePath = this.webBrowser1.Url.AbsolutePath;
if (myAbsolutePath == @"/")
{myFileName = "Test.txt";}
else
{ myFileName = Path.GetFileName(myAbsolutePath);
if (myFileName == String.Empty)
{int PosLastOneSlash,PosLastTwoSlash;
PosLastOneSlash = myAbsolutePath.LastIndexOf(@"/");
PosLastTwoSlash = myAbsolutePath.LastIndexOf(@"/",PosLastOneSlash - 1);
myFileName yAbsolutePath.Substring(PosLastTwoSlash+1,PosLastOneSlash - PosLastTwoSlash-1) + ".htm";} } }
else
{MessageBox.Show("这不是一种HTML 文献,无法查看其源文献。");
return;}
myFileName = @"C:\" + myFileName;
try
{ //将网页HTML 内容写入指定档案中
File.WriteAllText(myFileName,this.webBrowser1.DocumentText);
//使用记事本来启动刚刚所写入档案
System.Diagnostics.Process.Start("notepad.exe",myFileName);}
catch (Exception ex)
{MessageBox.Show(ex.Message);}
private void 打开OToolStripMenuItem_Click(object sender,EventArgs e)
{ try
{ if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{this.webBrowser1.Navigate(openFileDialog1.FileName);}
catch (Exception ex)
{ MessageBox.Show(ex.Message);} }
private void 打印PToolStripMenuItem_Click(object sender,EventArgs e)
{ this.webBrowser1.ShowPrintDialog();}
private void 打印预览VToolStripMenuItem_Click(object sender,EventArgs e)
{ this.webBrowser1.ShowPageSetupDialog();}
private void pageSetupMenuItem_Click(object sender,EventArgs e)
{ this.webBrowser1.ShowPageSetupDialog();}
private void 全屏显示ToolStripMenuItem_Click(object sender,EventArgs e)
{ this.Size = this.MaximumSize;} }}
展开阅读全文