Advertisement
Guest User

test-code

a guest
May 3rd, 2012
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.09 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. //using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9.  
  10. namespace test
  11. {
  12.     public partial class Form1 : Form
  13.     {
  14.         string google_q;
  15.         List<string> history = new List<string>();
  16.         bool dont_add_history = true;//dont add to history the first time
  17.  
  18.         public Form1()
  19.         {
  20.             google_q = "http://google.com/search?q=cache:";
  21.             InitializeComponent();
  22.         }
  23.         private void Form1_Load(object sender, EventArgs e)
  24.         {
  25.             webBrowser1.Navigate(google_q + "http://hackforums.net");
  26.         }
  27.         private void webBrowser1_Navigating(object sender, WebBrowserNavigatingEventArgs e)
  28.         {
  29.             string path = e.Url.OriginalString;// e.Url.PathAndQuery;
  30.             string host = textBox1.Text.StartsWith("http://") ? textBox1.Text.Substring(7) : textBox1.Text;
  31.             host = (host.Contains("/") ? host.Substring(0, host.IndexOf('/')) : host);
  32.             host = host.StartsWith("www.") ? host.Substring(4) : host;
  33.  
  34.             if (!path.StartsWith(google_q) && path.Contains(host))
  35.             {
  36.                 webBrowser1.Navigate(google_q + path);
  37.                 e.Cancel = true;
  38.             }
  39.             else if (path.Contains(host))
  40.             {
  41.                 textBox1.Text = e.Url.OriginalString.Substring(google_q.Length);
  42.                 if (!dont_add_history)//clicked back, dont add to history
  43.                 {
  44.                     history.Add(google_q + textBox1.Text);
  45.                     listView1.Items.Insert(0, new ListViewItem(textBox1.Text));
  46.                 }
  47.             }
  48.         }
  49.         private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
  50.         {
  51.             if (dont_add_history)
  52.                 dont_add_history = false;
  53.         }
  54.         private void textBox1_KeyDown(object sender, KeyEventArgs e)
  55.         {
  56.             if (e.KeyCode == Keys.Enter)
  57.                 webBrowser1.Navigate(google_q + textBox1.Text);
  58.         }
  59.         private void button1_Click(object sender, EventArgs e)
  60.         {
  61.             dont_add_history = true;
  62.             if (history.Count <= 1)
  63.                 return;
  64.             listView1.Items.RemoveAt(0);
  65.             history.RemoveAt(history.Count - 1);
  66.             webBrowser1.Navigate(history[history.Count-1]);
  67.         }
  68.         private void button2_Click(object sender, EventArgs e)
  69.         {
  70.             dont_add_history = true;
  71.             webBrowser1.Navigate(textBox1.Text);
  72.         }
  73.         private void listView1_SelectedIndexChanged(object sender, EventArgs e)
  74.         {
  75.             if (listView1.SelectedItems.Count == 0)
  76.                 return;
  77.             int index = listView1.SelectedItems[0].Index;
  78.             for (int i=0; i<index; i++)//removing previous history
  79.                 listView1.Items.RemoveAt(0);
  80.  
  81.             dont_add_history = true;
  82.             webBrowser1.Navigate(google_q + listView1.SelectedItems[0].Text);
  83.         }
  84.     }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement