千家信息网

如何用C#做浏览器源程序

发表于:2026-10-31 作者:千家信息网编辑
千家信息网最后更新 2026年10月31日,这篇文章主要讲解了"如何用C#做浏览器源程序",文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习"如何用C#做浏览器源程序"吧!C#做浏览器源程序了解C#源程
千家信息网最后更新 2026年10月31日如何用C#做浏览器源程序

这篇文章主要讲解了"如何用C#做浏览器源程序",文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习"如何用C#做浏览器源程序"吧!

C#做浏览器源程序

了解C#源程序代码,就可以比较容易编写一个属于自己的浏览器了,下面是用Visual C#做浏览器源程序代码,他具备了IE浏览器的一些常用的功能。

  1. using System ;

  2. using System.Drawing ;

  3. using System.Collections ;

  4. using System.ComponentModel ;

  5. using System.Windows.Forms ;

  6. using System.Data ;

  7. using AxSHDocVw ;

  8. public class Form1 : Form

  9. {

  10. private ToolBar toolBar1 ;

  11. private ToolBarButton tb1 ;

  12. private ToolBarButton tb2 ;

  13. private ToolBarButton tb3 ;

  14. private ToolBarButton tb4 ;

  15. private ToolBarButton tb5 ;

  16. private Label label1 ;

  17. private TextBox textBox1 ;

  18. private Button button1 ;

  19. private AxWebBrowser axWebBrowser1 ;

  20. private System.ComponentModel.Container components = null ;

  21. public Form1 ( )

  22. {

  23. InitializeComponent ( ) ;

  24. }

  25. //清除程序中使用过的资源

  26. protected override void Dispose ( bool disposing )

  27. {

  28. if ( disposing )

  29. {

  30. if ( components != null )

  31. {

  32. components.Dispose ( ) ;

  33. }

  34. }

  35. base.Dispose ( disposing ) ;

  36. }

  37. //初始化窗体中的各个组件

  38. private void InitializeComponent ( )

  39. {

  40. tb1 = new ToolBarButton ( ) ;

  41. tb2 = new ToolBarButton ( ) ;

  42. tb3 = new ToolBarButton ( ) ;

  43. toolBar1 = new ToolBar ( ) ;

  44. tb4 = new ToolBarButton ( ) ;

  45. tb5 = new ToolBarButton ( ) ;

  46. button1 = new Button ( ) ;

  47. textBox1 = new TextBox ( ) ;

  48. axWebBrowser1 = new AxWebBrowser ( ) ;

  49. label1 = new Label ( ) ;

  50. ( ( System.ComponentModel.ISupportInitialize )
    ( this.axWebBrowser1 ) ).BeginInit ( ) ;

  51. this.SuspendLayout ( ) ;

  52. tb1.Text = "后退" ;

  53. tb2.Text = "前进" ;

  54. tb3.Text = "停止" ;

  55. tb4.Text = "刷新" ;

  56. tb5.Text = "主页" ;

  57. toolBar1.Appearance = ToolBarAppearance.Flat ;

  58. toolBar1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle ;

  59. //在工具栏中加入按钮

  60. toolBar1.Buttons.Add ( tb1 ) ;

  61. toolBar1.Buttons.Add ( tb2 ) ;

  62. toolBar1.Buttons.Add ( tb3 ) ;

  63. toolBar1.Buttons.Add ( tb4 ) ;

  64. toolBar1.Buttons.Add ( tb5 ) ;

  65. toolBar1.DropDownArrows = true ;

  66. toolBar1.Name = "toolBar1" ;

  67. toolBar1.ShowToolTips = true ;

  68. toolBar1.Size = new System.Drawing.Size ( 612 , 39 ) ;

  69. toolBar1.TabIndex = 0 ;

  70. toolBar1.ButtonClick += new ToolBarButtonClickEventHandler ( toolBar1_ButtonClick ) ;

  71. //定位"转到"按钮组件与窗体的上、右边框保持一致

  72. button1.Anchor = ( AnchorStyles.Top | AnchorStyles.Right ) ;

  73. button1.DialogResult = DialogResult.OK ;

  74. button1.Location = new System.Drawing.Point ( 544 , 45 ) ;

  75. button1.Name = "button1" ;

  76. button1.Size = new System.Drawing.Size ( 40 , 23 ) ;

  77. button1.TabIndex = 3 ;

  78. button1.Text = "转到" ;

  79. button1.Click += new System.EventHandler ( button1_Click ) ;

  80. //定位地址文本框组件与窗体的上、左、右边框保持一致

  81. textBox1.Anchor = ( ( AnchorStyles.Top | AnchorStyles.Left )

  82. | AnchorStyles.Right ) ;

  83. textBox1.Location = new System.Drawing.Point ( 64 , 47 ) ;

  84. textBox1.Name = "textBox1" ;

  85. textBox1.Size = new System.Drawing.Size ( 464 , 21 ) ;

  86. textBox1.TabIndex = 2 ;

  87. textBox1.Text = "" ;

  88. //定位浏览器组件与窗体的上、下、左、右边框保持一致

  89. axWebBrowser1.Anchor = ( ( ( AnchorStyles.Top | AnchorStyles.Bottom )

  90. | AnchorStyles.Left )

  91. | AnchorStyles.Right ) ;

  92. axWebBrowser1.Enabled = true ;

  93. axWebBrowser1.Location = new System.Drawing.Point ( 0 , 72 ) ;

  94. axWebBrowser1.Size = new System.Drawing.Size ( 608 , 358 ) ;

  95. axWebBrowser1.TabIndex = 4 ;

  96. label1.Location = new System.Drawing.Point ( 16 , 48 ) ;

  97. label1.Name = "label1" ;

  98. label1.Size = new System.Drawing.Size ( 48 , 16 ) ;

  99. label1.TabIndex = 1 ;

  100. label1.Text = "地址:" ;

  101. this.AutoScaleBaseSize = new System.Drawing.Size ( 6 , 14 ) ;

  102. this.ClientSize = new System.Drawing.Size ( 612 , 433 ) ;

  103. this.Controls.Add ( axWebBrowser1 ) ;

  104. this.Controls.Add ( button1 ) ;

  105. this.Controls.Add ( textBox1 ) ;

  106. this.Controls.Add ( label1 ) ;

  107. this.Controls.Add ( toolBar1 ) ;

  108. this.FormBorderStyle = FormBorderStyle.FixedSingle ;

  109. this.Name = "Form1" ;

  110. this.Text = "visual C#做浏览器" ;

  111. ( ( System.ComponentModel.ISupportInitialize )
    ( this.axWebBrowser1 ) ).EndInit ( ) ;

  112. this.ResumeLayout ( false ) ;

  113. }

  114. static void Main ( )

  115. {

  116. Application.Run ( new Form1 ( ) ) ;

  117. }

  118. //实现浏览器主要功能

  119. private void toolBar1_ButtonClick
    ( object sender , ToolBarButtonClickEventArgs e )

  120. {

  121. //浏览器中的"后退"

  122. if ( e.Button == tb1 )

  123. {

  124. axWebBrowser1.GoBack ( ) ;

  125. }

  126. //浏览器中的"前进"

  127. if ( e.Button == tb2 )

  128. {

  129. axWebBrowser1.GoForward ( ) ;

  130. }

  131. //浏览器中的"停止"

  132. if ( e.Button == tb3 )

  133. {

  134. axWebBrowser1.Stop ( ) ;

  135. }

  136. //浏览器中的"刷新"

  137. if ( e.Button == tb4 )

  138. {

  139. axWebBrowser1.Refresh ( ) ;

  140. }

  141. //浏览器中的"主页"

  142. if ( e.Button == tb5 )

  143. {

  144. axWebBrowser1.GoHome ( ) ;

  145. }

  146. }

  147. //浏览指定的Web地址

  148. private void button1_Click ( object sender , System.EventArgs e )

  149. {

  150. System.Object nullObject = 0 ;

  151. string str = "" ;

  152. System.Object nullObjStr = str ;

  153. Cursor.Current = Cursors.WaitCursor ;

  154. axWebBrowser1.Navigate ( textBox1.Text , ref nullObject ,
    ref nullObjStr , ref nullObjStr , ref nullObjStr ) ;

  155. Cursor.Current = Cursors.Default ;

  156. }

  157. }

编译源程序和编译后的执行程序的运行界面在经过如下命令编译后,就可以得到可以自己的浏览器了

感谢各位的阅读,以上就是"如何用C#做浏览器源程序"的内容了,经过本文的学习后,相信大家对如何用C#做浏览器源程序这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是,小编将为大家推送更多相关知识点的文章,欢迎关注!

浏览 浏览器 源程序 C# 窗体 组件 一致 右边 地址 学习 定位 编译 主页 代码 内容 功能 按钮 程序 命令 就是 数据库的安全要保护哪些东西 数据库安全各自的含义是什么 生产安全数据库录入 数据库的安全性及管理 数据库安全策略包含哪些 海淀数据库安全审计系统 建立农村房屋安全信息数据库 易用的数据库客户端支持安全管理 连接数据库失败ssl安全错误 数据库的锁怎样保障安全 山东特亿宝互联网科技有限公司 互联网公司 科技公司 安徽鑫晟辉互联网科技 深圳天众互联网科技公司 互联网科技论坛 互联网科技公司介绍 茂名市互联网科技产业园 湖北码尼互联网科技有限公司电话 武汉健翔互联网络科技有限公司 米聚互联网科技南京有限公司排面 银川新华互联网科技学校联系电话 内蒙古九一互联网科技 高科技互联网发展前景如何 伊宁互联网科技做什么的 银行科技岗属于互联网吗 张召忠谈中国互联网科技 陕西云淼互联网科技公司 上海乐五互联网科技有限公司 互联网科技新闻 华人运通互联网科技公司 互联网科技有限公司 鑫亿盛互联网科技 奇酷互联网络科技公司 广西互联网科技公司 美国互联网前沿科技 青海省互联网新科技 阿里巴巴算科技企业还是互联网 江苏互联网智能科技软件 卡尔迅互联网科技有限公司 悟空问答互联网科技
0