Faizan Ahmed

Faizan Ahmed

  • NA
  • 32
  • 0

Replace ChromiumWebBrowser with Inter Explorer in .NET Desktop Applic

Apr 16 2024 8:53 AM
/*I have .Net Desktop Application that developed on .NET Framework 3.5 it’s using Inter Explorer for loading Web Pages but Now I need to use ChromiumWebBrowser 
in my Desktop Application I am sharing Code please guide where I have to change to replace ChromiumWebBrowser with Inter Explorer*/
//--Form1.Designer.cs CODE--
private void InitializeComponent()
        {
            this.components = new System.ComponentModel.Container();
            this.pnl_webBrowser = new System.Windows.Forms.Panel();
            this.webBrowse = new System.Windows.Forms.WebBrowser();
            this.timer1 = new System.Windows.Forms.Timer(this.components);
            this.WebLayOut = new System.Windows.Forms.TableLayoutPanel();
            this.tableLayoutPanel2 = new System.Windows.Forms.TableLayoutPanel();
            this.imgVideo = new System.Windows.Forms.PictureBox();
            this.imgCapture = new System.Windows.Forms.PictureBox();
            this.tablelayoutErrorshow = new System.Windows.Forms.TableLayoutPanel();
            this.lblErrorMessage = new System.Windows.Forms.Label();
            this.login_tblLayoutPanel = new System.Windows.Forms.TableLayoutPanel();
            this.tableLayoutPanel10 = new System.Windows.Forms.TableLayoutPanel();
            this.tableLayoutPanel11 = new System.Windows.Forms.TableLayoutPanel();
            this.loginLabel = new System.Windows.Forms.Label();
            this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel();
            this.loginPicture = new System.Windows.Forms.PictureBox();
            this.tableLayoutPanel12 = new System.Windows.Forms.TableLayoutPanel();
            this.tableLayoutPanel13 = new System.Windows.Forms.TableLayoutPanel();
            this.tableLayoutPanel14 = new System.Windows.Forms.TableLayoutPanel();
            this.tableLayoutPanel15 = new System.Windows.Forms.TableLayoutPanel();
            this.Exit_LogScr = new System.Windows.Forms.Button();
            this.logIn_Admin = new System.Windows.Forms.Button();
            this.lblLoginErrorMsg = new System.Windows.Forms.Label();
            this.tableLayoutPanel16 = new System.Windows.Forms.TableLayoutPanel();
            this.label4 = new System.Windows.Forms.Label();
            this.label5 = new System.Windows.Forms.Label();
            this.txt_AdminName = new System.Windows.Forms.TextBox();
            this.txt_AdminPass = new System.Windows.Forms.TextBox();
            this.pnl_webBrowser.SuspendLayout();
            this.WebLayOut.SuspendLayout();
            this.tableLayoutPanel2.SuspendLayout();
            ((System.ComponentModel.ISupportInitialize)(this.imgVideo)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.imgCapture)).BeginInit();
            this.tablelayoutErrorshow.SuspendLayout();
            this.login_tblLayoutPanel.SuspendLayout();
            this.tableLayoutPanel10.SuspendLayout();
            this.tableLayoutPanel11.SuspendLayout();
            this.tableLayoutPanel1.SuspendLayout();
            ((System.ComponentModel.ISupportInitialize)(this.loginPicture)).BeginInit();
            this.tableLayoutPanel12.SuspendLayout();
            this.tableLayoutPanel13.SuspendLayout();
            this.tableLayoutPanel14.SuspendLayout();
            this.tableLayoutPanel15.SuspendLayout();
            this.tableLayoutPanel16.SuspendLayout();
            this.SuspendLayout();
            // 
            // pnl_webBrowser
            // 
            this.pnl_webBrowser.Controls.Add(this.webBrowse);
            this.pnl_webBrowser.Dock = System.Windows.Forms.DockStyle.Fill;
            this.pnl_webBrowser.Location = new System.Drawing.Point(3, 3);
            this.pnl_webBrowser.Name = "pnl_webBrowser";
            this.pnl_webBrowser.Size = new System.Drawing.Size(267, 170);
            this.pnl_webBrowser.TabIndex = 13;
            // 
            // webBrowse
            // 
            this.webBrowse.Dock = System.Windows.Forms.DockStyle.Fill;
            this.webBrowse.Location = new System.Drawing.Point(0, 0);
            this.webBrowse.MinimumSize = new System.Drawing.Size(20, 20);
            this.webBrowse.Name = "webBrowse";
            this.webBrowse.ScriptErrorsSuppressed = true;
            this.webBrowse.Size = new System.Drawing.Size(267, 170);
            this.webBrowse.TabIndex = 0;
            this.webBrowse.DocumentCompleted += new System.Windows.Forms.WebBrowserDocumentCompletedEventHandler(this.webBrowse_DocumentCompleted);
            this.webBrowse.Navigated += new System.Windows.Forms.WebBrowserNavigatedEventHandler(this.webBrowse_Navigated);
           
            // 
            // WebLayOut
            // 
 
            this.WebLayOut.Controls.Add(this.pnl_webBrowser, 0, 0);
  
            
         

            // 
            // Form1
            // 
   
            this.pnl_webBrowser.ResumeLayout(false);
    

        }

 	private System.Windows.Forms.Panel pnl_webBrowser;
       
        private System.Windows.Forms.WebBrowser webBrowse;


//--Form1.cs CODE--

        private void webBrowse_Navigated(object sender, WebBrowserNavigatedEventArgs e)
        {
            string urlPath = e.Url.AbsolutePath;
            if (urlPath == "/paper/UserTestPaper.aspx")
            {
                this.WindowState = FormWindowState.Normal;
                this.FormBorderStyle = FormBorderStyle.None;
                this.Bounds = Screen.AllScreens[0].Bounds;
                TopMost = true;
                KillProcesses();
            }
            else
            {
                this.FormBorderStyle = FormBorderStyle.Sizable;
                this.WindowState = FormWindowState.Maximized;
                TopMost = false;
            }


            if (urlPath == "/paper/StudentVerification.aspx")
            {
                Timecount = 0;
                timer1.Start();
            }
            if (urlPath == "/paper/Exit.aspx")
            {
                Application.Exit();
            }
            if (urlPath == "/paper/Login.aspx")
            {
                this.Bounds = Screen.AllScreens[0].Bounds;
                this.FormBorderStyle = FormBorderStyle.Sizable;
                this.WindowState = FormWindowState.Maximized;

                login_tblLayoutPanel.Dock = DockStyle.Fill;
                login_tblLayoutPanel.Visible = true;
                WebLayOut.Visible = false;
                tablelayoutErrorshow.Visible = false;

                txt_AdminName.Focus();
                txt_AdminName.Multiline = false;
                txt_AdminPass.Multiline = false;
                txt_AdminName.Visible = true;
                txt_AdminPass.Visible = true;
            }
        }
        private void webBrowse_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            if (this.webBrowse.ReadyState != WebBrowserReadyState.Complete)
            {
                tablelayoutErrorshow.Visible = false;
                WebLayOut.Dock = DockStyle.Fill;
                pnl_webBrowser.Dock = DockStyle.Fill;
                WebLayOut.Visible = true;
                return;
            }
            else
            {
                string DocTitle = this.webBrowse.DocumentTitle;
                if (DocTitle.Contains("Not Found") || DocTitle.Contains("Navigation Canceled") 
                    || DocTitle.Contains("Can't reach this page"))
                {
                    tablelayoutErrorshow.Dock = DockStyle.Fill;
                    tablelayoutErrorshow.Visible = true;
                    lblErrorMessage.Text = "Unable to Connect to Server.";
                    WebLayOut.Visible = false;
                }
            }
        }


// web page load on click Button
private void logIn_Admin_Click(object sender, EventArgs e)
{
 webBrowse.Navigate(WebPortalLink);
}

 


Answers (1)