[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
  • @ lurch6661:
    but i will download the game
  • @ QM|T_JinX:
    cool
  • @ lurch6661:
    did you look into getting a new mic
  • @ QM|T_JinX:
    now not yet got one my self but i do got one lol
  • @ lurch6661:
    lol
  • @ QM|T_JinX:
    you got one /
  • @ lurch6661:
    gonna get one
  • @ lurch6661:
    need a wireless one
  • @ QM|T_JinX:
    well when you get your money maybe get one
  • @ QM|T_JinX:
    im gonna buy one this month but i also want to get the edg controler hahaha
  • @ QM|T_JinX:
    edge
  • @ QM|T_JinX:
    but let me know if you realy gonna install mw3 and if you want to play some matches we can work on a menu for you then
  • @ QM|T_JinX:
    im gonna watch a movie so catch you on the flip side
  • @ lurch6661:
    ok cool bro tc
  • @ lurch6661:
    i will download it for sure then
  • @ QM|T_JinX:
    keep in mind i do think there are free ones you maybe have to buy one and also dont do it on your main account make new one
  • @ ZockMock131:
    Hello there, is the Admin online?
  • @ QM|T_JinX:
    well im not a admin but maybe i can help /
  • @ ZockMock131:
    I want to delete my old account permantly bcs i dont use it anymore
  • @ QM|T_JinX:
    there is no option to delete a account for members im afraid
  • @ ZockMock131:
    Why is that bro
    ?
  • @ QM|T_JinX:
    not sure
  • Chat Bot:
    Christo has joined the room.
  • Chat Bot:
    nodikx is our newest member. Welcome!
  • Chat Bot:
    KrxzyMods is our newest member. Welcome!
    Chat Bot: KrxzyMods is our newest member. Welcome!