home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 2005 June (DVD) / DPPRO0605DVD.iso / Install / program files / Borland / BDS / 3.0 / Demos / CSharp / Applications / AX Web Browser / WebBrowserImpl.cs < prev    next >
Encoding:
Text File  |  2004-10-22  |  6.9 KB  |  207 lines

  1. /*********************************************************
  2. C# WebBrowser demo
  3. Example submitted by Chua Chee Wee, Singapore
  4.  
  5. Dependencies: AxInterop.SHDocVw.dll (aximp c:\windows\system\shdocvw.dll)
  6. **********************************************************/
  7. using System;
  8. using System.Drawing;
  9. using System.Collections;
  10. using System.ComponentModel;
  11. using System.Windows.Forms;
  12. using System.Data;
  13. using System.Reflection;
  14.  
  15.  
  16. namespace WebBrowserNamespace
  17. {
  18.     /// <summary>
  19.     /// Summary description for WinForm3.
  20.     /// </summary>
  21.     public class WebBrowserForm : System.Windows.Forms.Form
  22.     {
  23.         /// <summary>
  24.         /// Required designer variable.
  25.         /// </summary>
  26.         private System.ComponentModel.Container components = null;
  27.         private System.Windows.Forms.Panel panel1;
  28.         private System.Windows.Forms.Label label1;
  29.         private System.Windows.Forms.Panel panel2;
  30.         private System.Windows.Forms.Button btnViewWebPage;
  31.         private System.Windows.Forms.TextBox URL;
  32.         protected Object oMissing = System.Reflection.Missing.Value;
  33.  
  34.         private System.Windows.Forms.StatusBar statusBar;
  35.         private AxSHDocVw.AxWebBrowser WebBrowser;
  36.  
  37.         public WebBrowserForm()
  38.         {
  39.             //
  40.             // Required for Windows Form Designer support
  41.             //
  42.             InitializeComponent();
  43.  
  44.             //
  45.             // TODO: Add any constructor code after InitializeComponent call
  46.             //
  47.         }
  48.  
  49.         /// <summary>
  50.         /// Clean up any resources being used.
  51.         /// </summary>
  52.         protected override void Dispose( bool disposing )
  53.         {
  54.             if( disposing )
  55.             {
  56.                 if (components != null)
  57.                 {
  58.                     components.Dispose();
  59.                 }
  60.             }
  61.             base.Dispose( disposing );
  62.         }
  63.  
  64.         #region Windows Form Designer generated code
  65.         /// <summary>
  66.         /// Required method for Designer support - do not modify
  67.         /// the contents of this method with the code editor.
  68.         /// </summary>
  69.         
  70.         private void InitializeComponent()
  71.         {
  72.             System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(WebBrowserForm));
  73.             this.panel1 = new System.Windows.Forms.Panel();
  74.             this.URL = new System.Windows.Forms.TextBox();
  75.             this.panel2 = new System.Windows.Forms.Panel();
  76.             this.btnViewWebPage = new System.Windows.Forms.Button();
  77.             this.label1 = new System.Windows.Forms.Label();
  78.             this.statusBar = new System.Windows.Forms.StatusBar();
  79.             this.WebBrowser = new AxSHDocVw.AxWebBrowser();
  80.             this.panel1.SuspendLayout();
  81.             this.panel2.SuspendLayout();
  82.             ((System.ComponentModel.ISupportInitialize)(this.WebBrowser)).BeginInit();
  83.             this.SuspendLayout();
  84.             // 
  85.             // panel1
  86.             // 
  87.             this.panel1.Controls.Add(this.URL);
  88.             this.panel1.Controls.Add(this.panel2);
  89.             this.panel1.Controls.Add(this.label1);
  90.             this.panel1.Dock = System.Windows.Forms.DockStyle.Top;
  91.             this.panel1.Location = new System.Drawing.Point(0, 0);
  92.             this.panel1.Name = "panel1";
  93.             this.panel1.Size = new System.Drawing.Size(408, 21);
  94.             this.panel1.TabIndex = 2;
  95.             // 
  96.             // URL
  97.             // 
  98.             this.URL.Dock = System.Windows.Forms.DockStyle.Fill;
  99.             this.URL.Location = new System.Drawing.Point(160, 0);
  100.             this.URL.Name = "URL";
  101.             this.URL.Size = new System.Drawing.Size(168, 20);
  102.             this.URL.TabIndex = 2;
  103.             this.URL.Text = "http://www.borland.com/";
  104.             // 
  105.             // panel2
  106.             // 
  107.             this.panel2.Controls.Add(this.btnViewWebPage);
  108.             this.panel2.Dock = System.Windows.Forms.DockStyle.Right;
  109.             this.panel2.Location = new System.Drawing.Point(328, 0);
  110.             this.panel2.Name = "panel2";
  111.             this.panel2.Size = new System.Drawing.Size(80, 21);
  112.             this.panel2.TabIndex = 1;
  113.             // 
  114.             // btnViewWebPage
  115.             // 
  116.             this.btnViewWebPage.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
  117.             this.btnViewWebPage.Location = new System.Drawing.Point(0, 0);
  118.             this.btnViewWebPage.Name = "btnViewWebPage";
  119.             this.btnViewWebPage.Size = new System.Drawing.Size(75, 20);
  120.             this.btnViewWebPage.TabIndex = 0;
  121.             this.btnViewWebPage.Text = "Go!";
  122.             this.btnViewWebPage.Click += new System.EventHandler(this.btnViewWebPage_Click);
  123.             // 
  124.             // label1
  125.             // 
  126.             this.label1.Dock = System.Windows.Forms.DockStyle.Left;
  127.             this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
  128.             this.label1.Location = new System.Drawing.Point(0, 0);
  129.             this.label1.Name = "label1";
  130.             this.label1.Size = new System.Drawing.Size(160, 21);
  131.             this.label1.TabIndex = 0;
  132.             this.label1.Text = "Enter web address :  ";
  133.             // 
  134.             // statusBar
  135.             // 
  136.             this.statusBar.Location = new System.Drawing.Point(0, 217);
  137.             this.statusBar.Name = "statusBar";
  138.             this.statusBar.Size = new System.Drawing.Size(408, 19);
  139.             this.statusBar.TabIndex = 4;
  140.             // 
  141.             // WebBrowser
  142.             // 
  143.             this.WebBrowser.Dock = System.Windows.Forms.DockStyle.Fill;
  144.             this.WebBrowser.Enabled = true;
  145.             this.WebBrowser.Location = new System.Drawing.Point(0, 21);
  146.             this.WebBrowser.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("WebBrowser.OcxState")));
  147.             this.WebBrowser.Size = new System.Drawing.Size(408, 196);
  148.             this.WebBrowser.TabIndex = 5;
  149.             this.WebBrowser.NavigateComplete2 += new AxSHDocVw.DWebBrowserEvents2_NavigateComplete2EventHandler(this.WebBrowser_NavigateComplete2);
  150.             // 
  151.             // WebBrowserForm
  152.             // 
  153.             this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
  154.             this.ClientSize = new System.Drawing.Size(408, 236);
  155.             this.Controls.Add(this.WebBrowser);
  156.             this.Controls.Add(this.statusBar);
  157.             this.Controls.Add(this.panel1);
  158.             this.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
  159.             this.Name = "WebBrowserForm";
  160.             this.Text = "C# Web Browser";
  161.             this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
  162.             this.Load += new System.EventHandler(this.WinForm3_Load);
  163.             this.Closed += new System.EventHandler(this.WinForm3_Closed);
  164.             this.panel1.ResumeLayout(false);
  165.             this.panel2.ResumeLayout(false);
  166.             ((System.ComponentModel.ISupportInitialize)(this.WebBrowser)).EndInit();
  167.             this.ResumeLayout(false);
  168.         }
  169.         #endregion
  170.  
  171.         /// <summary>
  172.         /// The main entry point for the application.
  173.         /// </summary>
  174.         [STAThread]
  175.         static void Main()
  176.         {
  177.             Application.Run(new WebBrowserForm());
  178.         }
  179.  
  180.         private void LoadPage()
  181.         {
  182.           string WebURL = URL.Text;
  183.           WebBrowser.Navigate(WebURL, ref oMissing, ref oMissing,
  184.                               ref oMissing, ref oMissing);
  185.         }
  186.  
  187.         private void btnViewWebPage_Click(object sender, System.EventArgs e)
  188.         {
  189.           LoadPage();
  190.         }
  191.  
  192.         private void WinForm3_Load(object sender, System.EventArgs e)
  193.         {
  194.           LoadPage();
  195.         }
  196.         
  197.         private void WinForm3_Closed(object sender, System.EventArgs e)
  198.         {
  199.             
  200.         }
  201.  
  202.         private void WebBrowser_NavigateComplete2(object sender, AxSHDocVw.DWebBrowserEvents2_NavigateComplete2Event e) {
  203.          statusBar.Text = URL.Text+" loaded.";
  204.         }
  205.     }
  206. }
  207.