Show web browser on Winform/WPF with WebView2

DevNotes
0
WebView2 thư viện hỗ trợ mở trình duyệt trên winform/wpf thông qua control webview2
1. Thêm NugetPackge

2. Thêm Control vào winform
3. Code mẫu thêm vào một url sẵn

using System;
using System.Windows.Forms;
namespace WindowsFormsApp2
{
    public partial class WebPage : Form
    {
        public WebPage()
        {
            InitializeComponent();
            this.SizeChanged += WebPage_SizeChanged;
            InitializeWebView();
        }

        private void WebPage_SizeChanged(object sender, EventArgs e)
        {
            webViewControl.Height = this.Height;
            webViewControl.Width = this.Width;
        }

        private async void InitializeWebView()
        {
            await webViewControl.EnsureCoreWebView2Async(null);
            webViewControl.Source = new Uri("http://169.254.76.81");
        }
    }
}

Kết quả mẫu

Post a Comment

0 Comments
Post a Comment (0)
To Top