[C#] Web Browser Source

  • Hello Guest! Welcome to ConsoleCrunch, to help support our site check out the premium upgrades HERE! to get exclusive access to our hidden content.
  • Unable to load portions of the website...
    If you use an ad blocker addon, you should disable it because it interferes with several elements of the site and blocks more than just adverts.
  • Read Rules Before Posting Post Virus Scans with every program.

Elite_Modz

Active Poster
Retired Staff
Active Member
Console ID Poster
Dec 19, 2014
517
380
133
Crunch
Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Net;

namespace Browser1
{
  public partial class UserControl1 : UserControl
  {
  public UserControl1()
  {
  InitializeComponent();
  }

  private void UserControl1_Load(object sender, EventArgs e)
  {

  }

  #region Design
  public void Design_1()
  {
  //Progressbar for Loading
  progressBar1.Visible = true;
  progressBar2.Visible = true;

  //Side Panels
  panel_1.Visible = true;
  panel_2.Visible = true;
  }

  public void Design_2()
  {

  }
  #endregion

  #region Search
  public void Search_1()
  {
  try
  {
  if (String.IsNullOrEmpty(textBox1.Text))
  {

  }
  else
  {
  if (textBox1.Text.Contains("https://"))
  {
  Load_1();
  webBrowser1.ScriptErrorsSuppressed = true;
  webBrowser1.Navigate(textBox1.Text);
  //BrowserTitle();
  }
  else if (textBox1.Text.Contains("http://"))
  {
  Load_1();
  webBrowser1.ScriptErrorsSuppressed = true;
  webBrowser1.Navigate(textBox1.Text);
  //BrowserTitle();
  }
  else if (!textBox1.Text.Contains("."))
  {
  Load_1();
  webBrowser1.ScriptErrorsSuppressed = true;
  webBrowser1.Navigate("https://www.google.com/search?q=" + textBox1.Text);
  //BrowserTitle();
  }
  else
  {
  Load_1();
  webBrowser1.ScriptErrorsSuppressed = true;
  webBrowser1.Navigate("https://" + textBox1.Text);
  //BrowserTitle();
  }
  }
  }
  catch (Exception ex)
  {
  MessageBox.Show(ex.Message);
  }
  }

  public void Search_2()
  {

  }

  public void Load_1()
  {
  panel1.Enabled = false;
  }

  public static void BrowserTitle()
  {
  UserControl1 userControl1 = new UserControl1();
  //userControl1.BrowserUrl();
  //Form1.TabTitle(BrowserUrl());
  //MessageBox.Show(BrowserUrl());

  Form1 form1 = new Form1();
  form1.tabControl1.TabPages[form1.tabControl1.SelectedIndex].Text = userControl1.webBrowser1.DocumentTitle.ToString();
  form1.tabControl1.SelectedTab.Text = userControl1.webBrowser1.DocumentTitle.ToString();
  form1.tabControl1.Refresh();
  }
  #endregion

  public string BrowserUrl()
  {
  if (!String.IsNullOrEmpty(webBrowser1.Url.ToString()))
  {
  return GetWebPageTitle(webBrowser1.Url.ToString());
  }
  else
  {
  return null;
  }
  }

  public static string GetWebPageTitle(string url)
  {
  // Create a request to the url

  HttpWebRequest request = HttpWebRequest.Create(url) as HttpWebRequest;

  // If the request wasn’t an HTTP request (like a file), ignore it

  if (request == null) return null;

  // Use the user’s credentials

  request.UseDefaultCredentials = true;

  // Obtain a response from the server, if there was an error, return nothing

  HttpWebResponse response = null;

  try { response = request.GetResponse() as HttpWebResponse; }

  catch (WebException) { return null; }

  // Regular expression for an HTML title

  string regex = @"(?<=<title.*>)([\s\S]*)(?=</title>)";

  // If the correct HTML header exists for HTML text, continue

  if (new List<string>(response.Headers.AllKeys).Contains("Content-Type"))

  if (response.Headers["Content-Type"].StartsWith("text/html"))
  {
  // Download the page

  WebClient web = new WebClient();

  web.UseDefaultCredentials = true;

  string page = web.DownloadString(url);

  // Extract the title

  Regex ex = new Regex(regex, RegexOptions.IgnoreCase);

  return ex.Match(page).Value.Trim();
  }

  // Not a valid HTML page

  return null;

  }


  private void label2_Click(object sender, EventArgs e)
  {
  progressBar1.Visible = true;
  progressBar2.Visible = true;
  progressBar1.Value = 100;
  progressBar2.Value = 100;
  Search_1();
  }

  private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
  {
  if (e.KeyChar == (char)ConsoleKey.Enter)
  {
  Search_1();
  }
  }

  private void webBrowser1_DocumentCompleted_1(object sender, WebBrowserDocumentCompletedEventArgs e)
  {
  panel1.Enabled = true;
  }

  private void label5_Click(object sender, EventArgs e)
  {
  progressBar1.Visible = true;
  progressBar2.Visible = true;
  progressBar1.Value = 0;
  progressBar2.Value = 0;
  //BrowserTitle();
  }

  private void webBrowser1_NewWindow(object sender, CancelEventArgs e)
  {

  }
  }
}
 
General chit-chat
Help Users
  • Chat Bot:
    Christo has joined the room.
  • Chat Bot:
    QM|T_JinX has posted a new reply in the thread "Giveaways for everyone!".
  • @ lurch6661:
    zap hows it going
  • @ QM|T_JinX:
    all good how you
  • @ lurch6661:
    good in da hood
  • @ lurch6661:
    bored but good lol
  • @ QM|T_JinX:
    ;lol ya that suck
  • @ lurch6661:
    i can be the hunter or be the prey
  • @ lurch6661:
    lol
  • @ QM|T_JinX:
    lol
  • Chat Bot:
    ★ℳ℮ℳO_o̶ has joined the room.
  • Chat Bot:
    Christo has joined the room.
  • Chat Bot:
    Christo has joined the room.
  • Chat Bot:
    Kikkoy is our newest member. Welcome!
  • Chat Bot:
    sdfbdf is our newest member. Welcome!
  • Chat Bot:
    Christo has joined the room.
  • Chat Bot:
    Christo has joined the room.
  • @ lurch6661:
    got some wireless earbuds i hope they work lol
  • Chat Bot:
    EL PERRITO is our newest member. Welcome!
  • Chat Bot:
    DarkDemise01 is our newest member. Welcome!
  • @ QM|T_JinX:
    @lurch6661 cool bro
    @ QM|T_JinX: @lurch6661 cool bro