Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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;
- namespace test
- {
- public partial class Form1 : Form
- {
- string google_q;
- List<string> history = new List<string>();
- bool dont_add_history = true;//dont add to history the first time
- public Form1()
- {
- google_q = "http://google.com/search?q=cache:";
- InitializeComponent();
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- webBrowser1.Navigate(google_q + "http://hackforums.net");
- }
- private void webBrowser1_Navigating(object sender, WebBrowserNavigatingEventArgs e)
- {
- string path = e.Url.OriginalString;// e.Url.PathAndQuery;
- string host = textBox1.Text.StartsWith("http://") ? textBox1.Text.Substring(7) : textBox1.Text;
- host = (host.Contains("/") ? host.Substring(0, host.IndexOf('/')) : host);
- host = host.StartsWith("www.") ? host.Substring(4) : host;
- if (!path.StartsWith(google_q) && path.Contains(host))
- {
- webBrowser1.Navigate(google_q + path);
- e.Cancel = true;
- }
- else if (path.Contains(host))
- {
- textBox1.Text = e.Url.OriginalString.Substring(google_q.Length);
- if (!dont_add_history)//clicked back, dont add to history
- {
- history.Add(google_q + textBox1.Text);
- listView1.Items.Insert(0, new ListViewItem(textBox1.Text));
- }
- }
- }
- private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
- {
- if (dont_add_history)
- dont_add_history = false;
- }
- private void textBox1_KeyDown(object sender, KeyEventArgs e)
- {
- if (e.KeyCode == Keys.Enter)
- webBrowser1.Navigate(google_q + textBox1.Text);
- }
- private void button1_Click(object sender, EventArgs e)
- {
- dont_add_history = true;
- if (history.Count <= 1)
- return;
- listView1.Items.RemoveAt(0);
- history.RemoveAt(history.Count - 1);
- webBrowser1.Navigate(history[history.Count-1]);
- }
- private void button2_Click(object sender, EventArgs e)
- {
- dont_add_history = true;
- webBrowser1.Navigate(textBox1.Text);
- }
- private void listView1_SelectedIndexChanged(object sender, EventArgs e)
- {
- if (listView1.SelectedItems.Count == 0)
- return;
- int index = listView1.SelectedItems[0].Index;
- for (int i=0; i<index; i++)//removing previous history
- listView1.Items.RemoveAt(0);
- dont_add_history = true;
- webBrowser1.Navigate(google_q + listView1.SelectedItems[0].Text);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement