Windows application version of Google Search Engine

zhaozj2021-02-16  53

Many times I feel very troublesome with www.google.com to search for the website. After reading the MSDN's knowledge base, use C # written this Windows application version of the Google search engine, mainly calling Google's open Web Service, but search time is still Not very fast, but at least save the trouble of [opening] in a new window], the following is the source code of the program, although it is very long, but the key code is not much, and the brick is pushed.

//Form1.cs

Using system.drawing; using system.collections; using system.windows.form; 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 () {initializationComponent ();

Protected Override Void Dispose (bool disposing) {if (disponents! = 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.button1_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 to get help"; THIS.Label1.Click = new system.eventhandler (this.label1_click); // // label2 // this.label2.location = new system.drawing.point (8); this.label2.name = "label2 "; This.label2.tabindex = 4; this.Label2.text =" Please enter keywords: "; /// 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. Listbox1_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 button1_Click (object sender, System.EventArgs e) {try {sKey = "R1SnlcZQFHIBYlBCYdip3j1ERCvueU2Z"; 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

}

private void listBox1_DoubleClick (object sender, System.EventArgs e) {try {String url; url = listBox1.Text; Process p = Process.Start (@url);} catch (Exception ee) {MessageBox.Show (ee.Message) }}

转载请注明原文地址:https://www.9cbs.com/read-24680.html

New Post(0)