Advertisement
DrAungWinHtut

Browser and EnterKey

Mar 31st, 2022
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.69 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.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using CefSharp;
  11. using CefSharp.WinForms;
  12.  
  13.  
  14. namespace NewTools
  15. {
  16.     public partial class frmBrowser : Form
  17.     {
  18.         public frmBrowser()
  19.         {
  20.             InitializeComponent();
  21.            
  22.         }
  23.      
  24.  
  25.  
  26.        
  27.  
  28.  
  29.  
  30.         private void btnSearch_Click(object sender, EventArgs e)
  31.         {
  32.             funBrowse();
  33.         }
  34.  
  35.         private void txtAddress_KeyDown(object sender, KeyEventArgs e)
  36.         {
  37.             if (e.KeyCode == Keys.Enter)
  38.             {
  39.                 funBrowse();
  40.             }
  41.         }
  42.         private void funBrowse()
  43.         {
  44.             string sAddress = txtAddress.Text;
  45.             string sHeader = sAddress.Substring(0, 4);
  46.             Uri uri = new Uri(sAddress, UriKind.RelativeOrAbsolute);
  47.             if (!uri.IsAbsoluteUri)
  48.             {
  49.                 if (sHeader == "www.")
  50.                 {
  51.                     sAddress = "https://" + sAddress;
  52.                 }
  53.                 else
  54.                 {
  55.                     sAddress = "https://www." + sAddress;
  56.                 }
  57.                 Uri uri2 = new Uri(sAddress, UriKind.RelativeOrAbsolute);
  58.                 brsHomepage.Navigate(uri2);
  59.  
  60.             }
  61.             else
  62.             {
  63.                 brsHomepage.Navigate(uri);
  64.             }
  65.         }
  66.  
  67.         private void brsHomepage_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
  68.         {
  69.             MessageBox.Show("Open Complete");
  70.         }
  71.     }
  72. }
  73.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement