Form1.cs
上传用户:lxycoco
上传日期:2022-07-21
资源大小:38457k
文件大小:6k
源码类别:

C#编程

开发平台:

Others

  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. namespace WebBrowser
  8. {
  9. /// <summary>
  10. /// Summary description for Form1.
  11. /// </summary>
  12. public class Form1 : System.Windows.Forms.Form
  13. {
  14. private System.Windows.Forms.Panel panel1;
  15. private System.Windows.Forms.TextBox textUrl;
  16. private AxSHDocVw.AxWebBrowser axWebBrowser1;
  17. private System.Windows.Forms.Button buttonNavigate;
  18. private System.Windows.Forms.Button buttonBack;
  19. private System.Windows.Forms.Button buttonForward;
  20. private System.Windows.Forms.StatusBar statusBar;
  21. /// <summary>
  22. /// Required designer variable.
  23. /// </summary>
  24. private System.ComponentModel.Container components = null;
  25. public Form1()
  26. {
  27. //
  28. // Required for Windows Form Designer support
  29. //
  30. InitializeComponent();
  31. //
  32. // TODO: Add any constructor code after InitializeComponent call
  33. //
  34. }
  35. /// <summary>
  36. /// Clean up any resources being used.
  37. /// </summary>
  38. protected override void Dispose( bool disposing )
  39. {
  40. if( disposing )
  41. {
  42. if (components != null) 
  43. {
  44. components.Dispose();
  45. }
  46. }
  47. base.Dispose( disposing );
  48. }
  49. #region Windows Form Designer generated code
  50. /// <summary>
  51. /// Required method for Designer support - do not modify
  52. /// the contents of this method with the code editor.
  53. /// </summary>
  54. private void InitializeComponent()
  55. {
  56. System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
  57. this.panel1 = new System.Windows.Forms.Panel();
  58. this.buttonForward = new System.Windows.Forms.Button();
  59. this.buttonBack = new System.Windows.Forms.Button();
  60. this.buttonNavigate = new System.Windows.Forms.Button();
  61. this.textUrl = new System.Windows.Forms.TextBox();
  62. this.axWebBrowser1 = new AxSHDocVw.AxWebBrowser();
  63. this.statusBar = new System.Windows.Forms.StatusBar();
  64. this.panel1.SuspendLayout();
  65. ((System.ComponentModel.ISupportInitialize)(this.axWebBrowser1)).BeginInit();
  66. this.SuspendLayout();
  67. // 
  68. // panel1
  69. // 
  70. this.panel1.Controls.Add(this.buttonForward);
  71. this.panel1.Controls.Add(this.buttonBack);
  72. this.panel1.Controls.Add(this.buttonNavigate);
  73. this.panel1.Controls.Add(this.textUrl);
  74. this.panel1.Dock = System.Windows.Forms.DockStyle.Top;
  75. this.panel1.Location = new System.Drawing.Point(0, 0);
  76. this.panel1.Name = "panel1";
  77. this.panel1.Size = new System.Drawing.Size(512, 48);
  78. this.panel1.TabIndex = 0;
  79. // 
  80. // buttonForward
  81. // 
  82. this.buttonForward.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
  83. this.buttonForward.Location = new System.Drawing.Point(376, 8);
  84. this.buttonForward.Name = "buttonForward";
  85. this.buttonForward.Size = new System.Drawing.Size(56, 23);
  86. this.buttonForward.TabIndex = 3;
  87. this.buttonForward.Text = "Forward";
  88. this.buttonForward.Click += new System.EventHandler(this.OnForward);
  89. // 
  90. // buttonBack
  91. // 
  92. this.buttonBack.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
  93. this.buttonBack.Location = new System.Drawing.Point(320, 8);
  94. this.buttonBack.Name = "buttonBack";
  95. this.buttonBack.Size = new System.Drawing.Size(48, 23);
  96. this.buttonBack.TabIndex = 2;
  97. this.buttonBack.Text = "Back";
  98. this.buttonBack.Click += new System.EventHandler(this.OnBack);
  99. // 
  100. // buttonNavigate
  101. // 
  102. this.buttonNavigate.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
  103. this.buttonNavigate.Location = new System.Drawing.Point(240, 8);
  104. this.buttonNavigate.Name = "buttonNavigate";
  105. this.buttonNavigate.Size = new System.Drawing.Size(64, 23);
  106. this.buttonNavigate.TabIndex = 1;
  107. this.buttonNavigate.Text = "Navigate";
  108. this.buttonNavigate.Click += new System.EventHandler(this.OnNavigate);
  109. // 
  110. // textUrl
  111. // 
  112. this.textUrl.Location = new System.Drawing.Point(16, 8);
  113. this.textUrl.Name = "textUrl";
  114. this.textUrl.Size = new System.Drawing.Size(208, 20);
  115. this.textUrl.TabIndex = 0;
  116. this.textUrl.Text = "";
  117. // 
  118. // axWebBrowser1
  119. // 
  120. this.axWebBrowser1.Dock = System.Windows.Forms.DockStyle.Fill;
  121. this.axWebBrowser1.Enabled = true;
  122. this.axWebBrowser1.Location = new System.Drawing.Point(0, 48);
  123. this.axWebBrowser1.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("axWebBrowser1.OcxState")));
  124. this.axWebBrowser1.Size = new System.Drawing.Size(512, 261);
  125. this.axWebBrowser1.TabIndex = 1;
  126. this.axWebBrowser1.StatusTextChange += new AxSHDocVw.DWebBrowserEvents2_StatusTextChangeEventHandler(this.OnStatusChange);
  127. this.axWebBrowser1.DocumentComplete += new AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEventHandler(this.OnDocumentComplete);
  128. // 
  129. // statusBar
  130. // 
  131. this.statusBar.Location = new System.Drawing.Point(0, 287);
  132. this.statusBar.Name = "statusBar";
  133. this.statusBar.Size = new System.Drawing.Size(512, 22);
  134. this.statusBar.TabIndex = 2;
  135. this.statusBar.Text = "statusBar";
  136. // 
  137. // Form1
  138. // 
  139. this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
  140. this.ClientSize = new System.Drawing.Size(512, 309);
  141. this.Controls.Add(this.statusBar);
  142. this.Controls.Add(this.axWebBrowser1);
  143. this.Controls.Add(this.panel1);
  144. this.Name = "Form1";
  145. this.Text = "Simple Browser";
  146. this.panel1.ResumeLayout(false);
  147. ((System.ComponentModel.ISupportInitialize)(this.axWebBrowser1)).EndInit();
  148. this.ResumeLayout(false);
  149. }
  150. #endregion
  151. /// <summary>
  152. /// The main entry point for the application.
  153. /// </summary>
  154. [STAThread]
  155. static void Main() 
  156. {
  157. Application.Run(new Form1());
  158. }
  159. private void OnNavigate(object sender, System.EventArgs e)
  160. {
  161. object noArg = null;
  162. this.axWebBrowser1.Navigate(textUrl.Text, ref noArg, ref noArg, ref noArg, ref noArg);
  163. }
  164. private void OnBack(object sender, System.EventArgs e)
  165. {
  166. try
  167. {
  168. this.axWebBrowser1.GoBack();
  169. }
  170. catch
  171. {
  172. }
  173. }
  174. private void OnForward(object sender, System.EventArgs e)
  175. {
  176. try
  177. {
  178. axWebBrowser1.GoForward();
  179. }
  180. catch
  181. {
  182. }
  183. }
  184. private void OnStatusChange(object sender, AxSHDocVw.DWebBrowserEvents2_StatusTextChangeEvent e)
  185. {
  186. this.statusBar.Text = e.text;
  187. }
  188. private void OnDocumentComplete(object sender, AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEvent e)
  189. {
  190. this.textUrl.Text = e.uRL.ToString();
  191. }
  192. }
  193. }