Description :
We can know about the browsers IE,Firefox..etc.
We can also create our own browser. It is very easy one.
We need the add following reference
AxInterop.SHDocVw
The name space used for creating your own browser
using AxSHDocVw;
The following is the sample code for creating the browser
public partial class Form1 : Form
{
private AxWebBrowser Mybrowser;
private Button MygoButton;
private TextBox SearhaddressBox;
private Panel Mypanel1;
private Panel Mypanel2;
public Form1()
{
InitializeComponent();
Mypanel1 = new Panel();
Mypanel2 = new Panel();
Mybrowser = new AxWebBrowser();
Mybrowser.BeginInit();
this.SuspendLayout();
Mypanel1.SuspendLayout();
Mypanel2.SuspendLayout();
this.Text = "My own Web Browser";
Mypanel1.Size = new Size(300, 30);
Mypanel1.Dock = DockStyle.Top;
Mypanel2.Size = new Size(285, 240);
Mypanel2.Location = new Point(5, 31);
Mypanel2.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
Mybrowser.Dock = DockStyle.Fill;
SearhaddressBox = new TextBox();
SearhaddressBox.Size = new Size(260, 20);
SearhaddressBox.Location = new Point(5, 5);
SearhaddressBox.Anchor = AnchorStyles.Top | AnchorStyles.Right | AnchorStyles.Left;
MygoButton = new Button();
MygoButton.Location = new Point(270, 5);
MygoButton.Size = new Size(20, 20);
MygoButton.Anchor = AnchorStyles.Top | AnchorStyles.Right;
Mypanel1.Controls.AddRange(new Control[] { SearhaddressBox, MygoButton });
Mypanel2.Controls.Add(Mybrowser);
this.Controls.AddRange(new Control[] { Mypanel1, Mypanel2 });
Mybrowser.EndInit();
Mypanel1.ResumeLayout();
Mypanel2.ResumeLayout();
this.ResumeLayout();
MygoButton.Click += new EventHandler(goButton_Click);
Mybrowser.GoHome();
}
private void goButton_Click(object sender, EventArgs e)
{
object o = null;
Mybrowser.Navigate(SearhaddressBox.Text, ref o, ref o, ref o, ref o);
}
Code Explanation
1. Create instance of AxWebBrowser.
2. Assign the controls in it.
3. On the button click navicate the browser.
Regard
Prateek
Mr.Prateek u r genious !!!!!
ReplyDelete