日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
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 = "前進(jìn)" ;
  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. //定位“轉(zhuǎn)到”按鈕組件與窗體的上、右邊框保持一致
  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 = "轉(zhuǎn)到" ;
  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. //實現(xiàn)瀏覽器主要功能
  119. private void toolBar1_ButtonClick 
    ( object sender , ToolBarButtonClickEventArgs e )
  120. {
  121. //瀏覽器中的“后退”
  122. if ( e.Button == tb1 )
  123. {
  124. axWebBrowser1.GoBack ( ) ;
  125. }
  126. //瀏覽器中的“前進(jìn)”
  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. }

編譯源程序和編譯后的執(zhí)行程序的運行界面在經(jīng)過如下命令編譯后,就可以得到可以自己的瀏覽器了csc /t:winexe /r:AxSHDocVw.dll /r:SHDocVw.dll /r:system.dll/r:system.windows.forms.dll /r:system.drawing.dll brower.cs

總結(jié)
至此一個功能相對完備的“瀏覽器”就算完成了,其實用Visual C#做瀏覽器源程序的過程,也就是Visual C#中使用COM組件的過程。掌握了COM組件在Visual C#使用方法,就可以利用Visual C#編寫出功能更強(qiáng)大,適應(yīng)性更強(qiáng)的軟件來,但編寫的過程又十分的簡單。


文章名稱:C#做瀏覽器源程序
當(dāng)前地址:http://www.dlmjj.cn/article/djiesjj.html