Simple WebBrowser : Web Browser « GUI Windows Form « C# / C Sharp






Simple WebBrowser

/*
Professional Windows GUI Programming Using C#
by Jay Glynn, Csaba Torok, Richard Conway, Wahid Choudhury, 
   Zach Greenvoss, Shripad Kulkarni, Neil Whitlow

Publisher: Peer Information
ISBN: 1861007663
*/

using System;
using System.Windows.Forms;
using System.Drawing;
using AxSHDocVw;

public class WebBrowser : Form
{
   private AxWebBrowser browser;
   private Button goButton;
   private TextBox addressBox;
   private Panel panel1;
   private Panel panel2;

   public WebBrowser()
   {
      panel1 = new Panel();
      panel2 = new Panel();
      browser = new AxWebBrowser();
      browser.BeginInit();

      this.SuspendLayout();
      panel1.SuspendLayout();
      panel2.SuspendLayout();

      this.Text = "MyWebBrowser";
      panel1.Size = new Size(300, 30);
      panel1.Dock = DockStyle.Top;

      panel2.Size = new Size(285,240);
      panel2.Location = new Point(5, 31);
      panel2.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;

      browser.Dock = DockStyle.Fill;

      addressBox = new TextBox();
      addressBox.Size = new Size(260, 20);
      addressBox.Location = new Point(5,5);
      addressBox.Anchor = AnchorStyles.Top | AnchorStyles.Right | AnchorStyles.Left;

      goButton = new Button();
      goButton.Image = Image.FromFile("Arrow.ico");
      goButton.Location = new Point(270,5);
      goButton.Size = new Size(20,20);
      goButton.Anchor = AnchorStyles.Top | AnchorStyles.Right;

      panel1.Controls.AddRange(new Control[] { addressBox, goButton });
      panel2.Controls.Add(browser);
      this.Controls.AddRange(new Control[] { panel1, panel2 });

      browser.EndInit();
      panel1.ResumeLayout();
      panel2.ResumeLayout();
      this.ResumeLayout();

      goButton.Click += new EventHandler(goButton_Click);
      browser.GoHome();
   }

   private void goButton_Click(object sender, EventArgs e)
   {
      object o = null;
      browser.Navigate(addressBox.Text, ref o, ref o, ref o, ref o);
   }

   [STAThread]
   public static void Main()
   {
      Application.Run(new WebBrowser());
   }
}

           
       








Related examples in the same category

1.WebBrowser in action
2.My Web BrowserMy Web Browser
3.Web Browser usual actions