It is often difficult to search for a website using www.google.com. After reading the msdn knowledge base, I used C # To write the Google search engine for this Windows application version, it mainly calls the Web Service opened by Google, but the search speed is not very fast, but at least it saves the trouble of right-clicking [open in a new window]. The following is the source code of the program, although it is quite long, there are not many key codes.
// Form1.cs
Using system;
Using system. drawing;
Using system. collections;
Using system. componentmodel;
Using system. Windows. forms;
Using system. Data;
Using system. diagnostics;
Namespace windowsapplication2
{
Public class form1: system. Windows. Forms. Form
{
Private system. Windows. Forms. textbox textbox2;
Private system. Windows. Forms. Button button1;
Private system. Windows. Forms. Label label1;
Private system. Windows. Forms. Label label2;
Private system. Windows. Forms. ListBox listbox1;
Private string skey;
Private system. componentmodel. Container components = NULL;
Public form1 ()
{
Initializecomponent ();
}
Protected override void dispose (bool disposing)
{
If (disposing)
{
If (components! = NULL)
{
Components. Dispose ();
}
}
Base. Dispose (disposing );
}
# Region windows Form Designer generated code
Private void initializecomponent ()
{
This. textbox2 = new system. Windows. Forms. Textbox ();
This. button1 = new system. Windows. Forms. Button ();
This. label1 = new system. Windows. Forms. Label ();
This. label2 = new system. Windows. Forms. Label ();
This. listbox1 = new system. Windows. Forms. ListBox ();
This. suspendlayout ();
//
// Textbox2
//
This. textbox2.location = new system. Drawing. Point (8, 32 );
This. textbox2.name = "textbox2 ";
This. textbox2.size = new system. Drawing. Size (240, 21 );
This. textbox2.tabindex = 1;
This. textbox2.text = "ERP ";
//
// Button1
//
This. button1.location = new system. Drawing. Point (264, 32 );
This. button1.name = "button1 ";
This. button1.tabindex = 2;
This. button1.text = "Search ";
This. button1.click + = new system. eventhandler (this. button#click );
//
// Label1
//
This. label1.backcolor = system. Drawing. systemcolors. Info;
This. label1.location = new system. Drawing. Point (136, 8 );
This. label1.name = "label1 ";
This. label1.size = new system. Drawing. Size (104, 16 );
This. label1.tabindex = 3;
This. label1.text = "Click here for help ";
This. label1.click + = new system. eventhandler (this. labelease click );
//
// Label2
//
This. label2.location = new system. Drawing. Point (8, 8 );
This. label2.name = "label2 ";
This. label2.tabindex = 4;
This. label2.text = "Enter the Keyword :";
//
// Listbox1
//
This. listbox1.horizontalscrollbar = true;
This. listbox1.itemheight = 12;
This. listbox1.location = new system. Drawing. Point (8, 64 );
This. listbox1.name = "listbox1 ";
This. listbox1.size = new system. Drawing. Size (360,292 );
This. listbox1.tabindex = 5;
This. listbox1.doubleclick + = new system. eventhandler (this. listbox#doubleclick );
//
// Form1
//
This. acceptbutton = This. button1;
This. autoscalebasesize = new system. Drawing. Size (6, 14 );
This. clientsize = new system. Drawing. Size (376,365 );
This. Controls. Add (this. listbox1 );
This. Controls. Add (this. label2 );
This. Controls. Add (this. label1 );
This. Controls. Add (this. button1 );
This. Controls. Add (this. textbox2 );
This. Name = "form1 ";
This. Text = "Google search engine V1.0 by yzwgh@sina.com ";
This. resumelayout (false );
}
# Endregion
[Stathread]
Static void main ()
{
Application. Run (New form1 ());
}
Private void button#click (Object sender, system. eventargs E)
{
Try
{
Skey = "r1snlczjwhibylbcydip3j1ercvueu2z ";
Googleapi. googlesearchservice S = new googleapi. googlesearchservice ();
Googleapi. googlesearchresult r = S. dogooglesearch (skey, textbox2.text,
0, 10, false, "", false ,"","","");
Googleapi. resultelement [] Re = R. resultelements;
This. listbox1.items. Clear ();
For (INT I = 0; I <Re. length; I ++)
{
This. listbox1.items. Add (object) (Re [I]. Title ));
This. listbox1.items. Add (object) (Re [I]. url ));
}
}
Catch (exception EEE)
{
MessageBox. Show (EEE. Message, this. Text );
}
}
Private void listboxshortdoubleclick (Object sender, system. eventargs E)
{
Try
{
String URL;
Url = listbox1.text;
PROCESS p = process. Start (@ URL );
}
Catch (exception ee)
{
MessageBox. Show (EE. Message );
}
}
Private void labelease click (Object sender, system. eventargs E)
{
String S;
S = This. Text + "/N ";
S = S + "Author: yzwgh/N ";
S = S + "E: yzwgh@sina.com/N ";
S = S + "double-click the following URL to open the corresponding link. ";
MessageBox. Show (S, this. Text );
}
}
}
Trackback: http://tb.blog.csdn.net/TrackBack.aspx? Postid = 632775