www.pudn.com > mygoogle_source.rar > Form1.cs, change:2002-04-28,size:9448b


using System; 
using System.Drawing; 
using System.Collections; 
using System.ComponentModel; 
using System.Windows.Forms; 
using System.Data; 
using System.IO; 
 
namespace MyGoogle 
{ 
	/// <summary> 
	/// Form1에 대한 요약 설명입니다. 
	/// </summary> 
	public class Form1 : System.Windows.Forms.Form 
	{ 
		private System.Windows.Forms.PictureBox pictureBox1; 
		private System.Windows.Forms.Label label1; 
		private System.Windows.Forms.TextBox textSearch; 
		private AxSHDocVw.AxWebBrowser WebBrowser; 
		private System.Windows.Forms.Button buttonSearch; 
		private System.Windows.Forms.Label labelSearchText; 
		private System.Windows.Forms.Label labelSearchResult; 
		private System.Windows.Forms.LinkLabel linkLabel1; 
		/// <summary> 
		/// 필수 디자이너 변수입니다. 
		/// </summary> 
		private System.ComponentModel.Container components = null; 
 
		public Form1() 
		{ 
			// 
			// Windows Form 디자이너 지원에 필요합니다. 
			// 
			InitializeComponent(); 
 
			// 
			// TODO: InitializeComponent를 호출한 다음 생성자 코드를 추가합니다. 
			// 
		} 
 
		/// <summary> 
		/// 사용 중인 모든 리소스를 정리합니다. 
		/// </summary> 
		protected override void Dispose( bool disposing ) 
		{ 
			if( disposing ) 
			{ 
				if (components != null)  
				{ 
					components.Dispose(); 
				} 
			} 
			base.Dispose( disposing ); 
		} 
 
		#region Windows Form Designer generated code 
		/// <summary> 
		/// 디자이너 지원에 필요한 메서드입니다. 
		/// 이 메서드의 내용을 코드 편집기로 수정하지 마십시오. 
		/// </summary> 
		private void InitializeComponent() 
		{ 
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1)); 
			this.pictureBox1 = new System.Windows.Forms.PictureBox(); 
			this.label1 = new System.Windows.Forms.Label(); 
			this.textSearch = new System.Windows.Forms.TextBox(); 
			this.buttonSearch = new System.Windows.Forms.Button(); 
			this.labelSearchText = new System.Windows.Forms.Label(); 
			this.WebBrowser = new AxSHDocVw.AxWebBrowser(); 
			this.labelSearchResult = new System.Windows.Forms.Label(); 
			this.linkLabel1 = new System.Windows.Forms.LinkLabel(); 
			((System.ComponentModel.ISupportInitialize)(this.WebBrowser)).BeginInit(); 
			this.SuspendLayout(); 
			//  
			// pictureBox1 
			//  
			this.pictureBox1.Image = ((System.Drawing.Bitmap)(resources.GetObject("pictureBox1.Image"))); 
			this.pictureBox1.Location = new System.Drawing.Point(8, 8); 
			this.pictureBox1.Name = "pictureBox1"; 
			this.pictureBox1.Size = new System.Drawing.Size(200, 80); 
			this.pictureBox1.TabIndex = 0; 
			this.pictureBox1.TabStop = false; 
			//  
			// label1 
			//  
			this.label1.Location = new System.Drawing.Point(216, 16); 
			this.label1.Name = "label1"; 
			this.label1.Size = new System.Drawing.Size(96, 16); 
			this.label1.TabIndex = 1; 
			this.label1.Text = "Search Text"; 
			//  
			// textSearch 
			//  
			this.textSearch.Location = new System.Drawing.Point(216, 32); 
			this.textSearch.Name = "textSearch"; 
			this.textSearch.Size = new System.Drawing.Size(216, 21); 
			this.textSearch.TabIndex = 1; 
			this.textSearch.Text = ""; 
			//  
			// buttonSearch 
			//  
			this.buttonSearch.BackColor = System.Drawing.SystemColors.Control; 
			this.buttonSearch.Location = new System.Drawing.Point(440, 32); 
			this.buttonSearch.Name = "buttonSearch"; 
			this.buttonSearch.Size = new System.Drawing.Size(75, 24); 
			this.buttonSearch.TabIndex = 2; 
			this.buttonSearch.Text = "Search!"; 
			this.buttonSearch.Click += new System.EventHandler(this.buttonSearch_Click); 
			//  
			// labelSearchText 
			//  
			this.labelSearchText.BackColor = System.Drawing.Color.RoyalBlue; 
			this.labelSearchText.ForeColor = System.Drawing.Color.White; 
			this.labelSearchText.Location = new System.Drawing.Point(8, 96); 
			this.labelSearchText.Name = "labelSearchText"; 
			this.labelSearchText.Size = new System.Drawing.Size(192, 24); 
			this.labelSearchText.TabIndex = 5; 
			this.labelSearchText.Text = "Result"; 
			this.labelSearchText.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; 
			//  
			// WebBrowser 
			//  
			this.WebBrowser.Anchor = (((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)  
				| System.Windows.Forms.AnchorStyles.Left)  
				| System.Windows.Forms.AnchorStyles.Right); 
			this.WebBrowser.Enabled = true; 
			this.WebBrowser.Location = new System.Drawing.Point(8, 128); 
			this.WebBrowser.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("WebBrowser.OcxState"))); 
			this.WebBrowser.Size = new System.Drawing.Size(640, 304); 
			this.WebBrowser.TabIndex = 6; 
			//  
			// labelSearchResult 
			//  
			this.labelSearchResult.Anchor = ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)  
				| System.Windows.Forms.AnchorStyles.Right); 
			this.labelSearchResult.BackColor = System.Drawing.Color.RoyalBlue; 
			this.labelSearchResult.ForeColor = System.Drawing.Color.White; 
			this.labelSearchResult.Location = new System.Drawing.Point(200, 96); 
			this.labelSearchResult.Name = "labelSearchResult"; 
			this.labelSearchResult.Size = new System.Drawing.Size(448, 24); 
			this.labelSearchResult.TabIndex = 7; 
			this.labelSearchResult.TextAlign = System.Drawing.ContentAlignment.MiddleRight; 
			//  
			// linkLabel1 
			//  
			this.linkLabel1.Location = new System.Drawing.Point(216, 64); 
			this.linkLabel1.Name = "linkLabel1"; 
			this.linkLabel1.Size = new System.Drawing.Size(296, 16); 
			this.linkLabel1.TabIndex = 8; 
			this.linkLabel1.TabStop = true; 
			this.linkLabel1.Text = "Google API Homepage"; 
			this.linkLabel1.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.linkLabel1_LinkClicked); 
			//  
			// Form1 
			//  
			this.AcceptButton = this.buttonSearch; 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14); 
			this.BackColor = System.Drawing.Color.White; 
			this.ClientSize = new System.Drawing.Size(656, 437); 
			this.Controls.AddRange(new System.Windows.Forms.Control[] { 
																		  this.linkLabel1, 
																		  this.labelSearchResult, 
																		  this.WebBrowser, 
																		  this.labelSearchText, 
																		  this.buttonSearch, 
																		  this.textSearch, 
																		  this.label1, 
																		  this.pictureBox1}); 
			this.Name = "Form1"; 
			this.Text = "MyGoogle Service"; 
			((System.ComponentModel.ISupportInitialize)(this.WebBrowser)).EndInit(); 
			this.ResumeLayout(false); 
 
		} 
		#endregion 
 
		/// <summary> 
		/// 해당 응용 프로그램의 주 진입점입니다. 
		/// </summary> 
		[STAThread] 
		static void Main()  
		{ 
			Application.Run(new Form1()); 
		} 
 
		private void buttonSearch_Click(object sender, System.EventArgs e) 
		{ 
			// before search 
			// 
			labelSearchText.Text = "Searching..."; 
			labelSearchText.Update(); 
 
 
			// create Google Search object 
			// 
			GoogleSearchService s = new GoogleSearchService(); 
			GoogleSearchResult r; 
 
 
			// call search function 
			// 
			r = s.doGoogleSearch( 
				"",  
				textSearch.Text,  
				0,  
				10,  
				false, "", false, "", "", ""); 
 
 
			// create HTML document to show result 
			// 
			string strFile = "result.html"; 
			StreamWriter sw = File.CreateText(strFile); 
 
 
			// Header inforamtion 
			// 
			sw.WriteLine("<HTML><HEAD><style>	BODY { font-family : Verdana, Geneva, Arial, Helvetica, sans-serif; font-size : 9pt; color : #000000; SCROLLBAR-FACE-COLOR: white; SCROLLBAR-HIGHLIGHT-COLOR: #003366; SCROLLBAR-SHADOW-COLOR: #003366; SCROLLBAR-3DLIGHT-COLOR: #f9f9f9; SCROLLBAR-ARROW-COLOR: #003366; SCROLLBAR-TRACK-COLOR: white; SCROLLBAR-DARKSHADOW-COLOR: #f9f9f9 }</style></HEAD><BODY>"); 
 
 
			// Category  
			// 
			foreach(DirectoryCategory dc in r.directoryCategories) 
			{ 
				sw.Write("<b>Category</b> : "); 
				sw.WriteLine(dc.fullViewableName); 
				sw.WriteLine("<br><br><br>"); 
			} 
 
 
			// iterate items 
			// 
			foreach(ResultElement re in r.resultElements) 
			{ 
				// Title 
				// 
				string strTitle = "<a href=\"" + re.URL + "\">" + re.title + "</a><br>"; 
				sw.WriteLine(strTitle); 
				 
				// snippet 
				// 
				string strSnippet = re.snippet +"<br>"; 
				sw.WriteLine(strSnippet); 
 
				// link and cache size 
				// 
				string strLink = "<a href=\"" + re.URL + "\">" + re.URL + "</a> - " + re.cachedSize + "<br><br>"; 
				sw.WriteLine(strLink); 
 
				// 2 line 
				// 
				sw.WriteLine("<br><br>"); 
			} 
 
 
			// file close 
			// 
			sw.Close(); 
 
			 
			// result inforamtion 
			// 
			labelSearchText.Text = textSearch.Text + " 's web search"; 
 
			int estResults = r.estimatedTotalResultsCount; 
			double ldTime = r.searchTime; 
			labelSearchResult.Text = "Total " + Convert.ToString(estResults) + "  " + "1 - 10 seach result  Total time:" + Convert.ToString(ldTime); 
 
 
			// browsing! 
			// 
			object obj = null; 
			DirectoryInfo di = new DirectoryInfo(Environment.CurrentDirectory); 
			string strFilePath = di.FullName + "\\" + strFile; 
			WebBrowser.Navigate(strFilePath, ref obj, ref obj, ref obj, ref obj); 
		} 
 
 
		// Google API homepage 
		// 
		private void linkLabel1_LinkClicked(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e) 
		{ 
			object obj = null; 
 
			WebBrowser.Navigate("http://www.google.com/apis/", ref obj, ref obj, ref obj, ref obj); 
		} 
	} 
}