Click here to Skip to main content
15,939,243 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hai,

I am developing a project for google search option in the windows application.In my project I am having some doubts.Below is the sample code. I am getting the error in "webbrowser".

"An object reference is required for the non-static field, method, or property 'System.Windows.Forms.WebBrowser.GoSearch()'".<br />

similarly i am getting error in WebBrowser.GoBack(),WebBrowser.GoForward(),WebBrowser.Navigate(string).
Please rectify this.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace WINDOWS_APPLICATION_GOOGLE_SEARCH
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (textBox1.Text.Trim().Length==0)
	  {
	  label1.Text = "Please enter text to search";
	  return;
	  }
	  else
	  {
	  string sridharan = "http://www.google.com/search?q=" + textBox1.Text;
	  WebBrowser.Navigate(sridharan);
               
	  }
        }

        private void button4_Click(object sender, EventArgs e)
        {
            WebBrowser.GoBack();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            WebBrowser.GoForward();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            WebBrowser.GoSearch();
        }
    }
}
Posted
Updated 5-Apr-11 23:12pm
v2

I can't see an instance of WebBrowser in your code.
There a two ways to get one.
1) Drag Webrowser from toolbox to your form
2) do it programamtically

WebBrowser myBrowser = new WebBrowser();
myBrowser.Parent = myform; // or whereever you want to show it
//myBrowser.allTheOtherPropertiesIwantToSet...

// some more code
myBrowser.navigate("http://....");
 
Share this answer
 
v3
Comments
aravindkrgec 6-Apr-11 5:34am    
WebBrowser is the ame of the control
Michel [mjbohn] 6-Apr-11 6:25am    
sorry, got confused by the name. It should work the way you implemented.
I think you missed something in this code. It works good with me.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900