C#+WebView2编程开发及打包运行

xingyun86 2023-2-23 455

C#+WebView2编程开发及打包运行

1.创建.net framework 4.8以上winform应用程序

2.nuget安装Microsoft.Windows.WebView2

3.Tools->Options->General->勾选Auto Hie button affects active tool window only

4.打开.form,工具箱可见WebView2控件,添加到form

5.编辑样例代码

 public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            textBoxUrl.Text = "https://www.baidu.com";
            webView2Browser.Source = new Uri(textBoxUrl.Text);
        }
        private void buttonGo_Click(object sender, EventArgs e)
        {
            string url = textBoxUrl.Text;
            webView2Browser.CoreWebView2.Navigate(textBoxUrl.Text);
        }
    }

6.运行发现,显示白屏。

7.安装WebView2 Runtime

分发应用和 WebView2 运行时 - Microsoft Edge Development | Microsoft Learn

WebView2 - Microsoft Edge Developer

8.再次运行


×
打赏作者
最新回复 (0)
只看楼主
全部楼主
返回