WebView2 in Windows Forms does not Navigate ?

vmars316 621 Reputation points
2020-10-14T15:37:04.8+00:00

Tia ;
In Getting started with WebView2 in Windows Forms apps Step 3.4
Program compliles ok , But doesnt Navigate to https://www.microsoft.com .
Neither does it Navigate on goButton_Click .
Code Below , Form1.Designer.cs followed by Form1.cs .

            this.webView.BackColor = System.Drawing.SystemColors.ActiveCaption;
            this.webView.Location = new System.Drawing.Point(12, 55);
            this.webView.Name = "webView";
            this.webView.Size = new System.Drawing.Size(1115, 426);
            this.webView.Source = new System.Uri("https://www.microsoft.com", System.UriKind.Absolute);
            this.webView.TabIndex = 0;
            this.webView.Text = "webView";
            this.webView.ZoomFactor = 1D;

/////////////////////////////////////////////////////////////////////

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Microsoft.Web.WebView2.Core;

namespace WinFormsGettngStarted
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            this.Resize += new System.EventHandler(this.Form_Resize);
            webView = new Microsoft.Web.WebView2.WinForms.WebView2();

        }
        private void Form_Resize(object sender, EventArgs e)
        {
            webView.Size = this.ClientSize - new System.Drawing.Size(webView.Location);
            goButton.Left = this.ClientSize.Width - goButton.Width;
            addressBar.Width = goButton.Left - addressBar.Left;
        }
            private void goButton_Click(object sender, EventArgs e)
        {
            if (webView != null && webView.CoreWebView2 != null)
            {
                webView.CoreWebView2.Navigate(addressBar.Text);
            }
        }

        private void addressBar_TextChanged(object sender, EventArgs e)
        {

        }

    }
}
Developer technologies Windows Forms
{count} votes

Accepted answer
  1. Daniel Zhang-MSFT 9,651 Reputation points
    2020-10-15T04:14:55.457+00:00

    Hi vmars316,
    I made a test by following this document and I have the same problem as you.
    I try to download and install Microsoft Edge Beta channel instead of Microsoft Edge Canary channel, it worked fine.
    So you can try Microsoft Edge Beta channel.
    Best Regards,
    Daniel Zhang


    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. vmars316 621 Reputation points
    2020-10-15T16:16:08.63+00:00

    Thanks Daniel ;
    Beta verson solved the startupPage problem .
    But now the 'private void Form_Resize' doesn't work .
    And the 'private void goButton_Click' doesn't even execute .

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    using Microsoft.Web.WebView2.Core;
    
    namespace WinFormsGettngStarted
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
                this.Resize += new System.EventHandler(this.Form_Resize);
                webView = new Microsoft.Web.WebView2.WinForms.WebView2();
    
            }
                private void Form_Resize(object sender, EventArgs e)
            {
                webView.Size = this.ClientSize - new System.Drawing.Size(webView.Location);
                goButton.Left = this.ClientSize.Width - goButton.Width;
                addressBar.Width = goButton.Left - addressBar.Left;
                MessageBox.Show("private void Form_Resize");
            }
                private void goButton_Click(object sender, EventArgs e)
            {
                if (webView != null && webView.CoreWebView2 != null)
                {
                    MessageBox.Show("private void goButton_Click");
                    webView.CoreWebView2.Navigate(addressBar.Text);
                }
            }
    
            private void addressBar_TextChanged(object sender, EventArgs e)
            {
    
            }
    
        } // class Form1
    } // namespace WinFormsGettngStarted
    

    Tia

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.