• 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.

[C#] Web Browser Source

Elite_Modz

Active Poster
Retired Staff
Active Member
Console ID Poster
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:
    Christo has joined the room.
  • Chat Bot:
    789betmiami is our newest member. Welcome!
  • Chat Bot:
    QM|T_JinX has joined the room.
  • Chat Bot:
    Christo has joined the room.
  • Chat Bot:
    cPwqA is our newest member. Welcome!
  • Chat Bot:
    keonhacaifootball is our newest member. Welcome!
  • Chat Bot:
    QM|T_JinX has joined the room.
  • Chat Bot:
    Keonhacai5vip11 is our newest member. Welcome!
  • Chat Bot:
    smoore99 is our newest member. Welcome!
  • Chat Bot:
    Pagliosa is our newest member. Welcome!
  • Chat Bot:
    QM|T_JinX has joined the room.
  • Chat Bot:
    prototypefox is our newest member. Welcome!
  • Chat Bot:
    maogege is our newest member. Welcome!
  • Chat Bot:
    ShadowPsy974 is our newest member. Welcome!
  • Chat Bot:
    Ghost8099 is our newest member. Welcome!
  • @ Ghost8099:
    Yurrrrrr
  • @ Ghost8099:
    Can we get a new link here brotha
  • Chat Bot:
    Mason Fo has left the room.
  • Chat Bot:
    QM|T_JinX has joined the room.
  • Chat Bot:
    wzxcvcv is our newest member. Welcome!
  • Chat Bot:
    cnood is our newest member. Welcome!
  • Chat Bot:
    zoumar is our newest member. Welcome!
  • Chat Bot:
    bestsmmlike is our newest member. Welcome!
      Chat Bot: bestsmmlike is our newest member. Welcome!
      Back
      Top