using Microsoft.Web.WebView2.WinForms; using Microsoft.Web.WebView2.Core; namespace EdgeVoyager { public partial class Form1 : Form { public Form1() { InitializeComponent(); InitializeAsync(); } async void InitializeAsync() { await webView21.EnsureCoreWebView2Async(null); webView21.CoreWebView2.Navigate("https://cn.bing.com/?mkt=zh-CN"); } private void back_button_Click(object sender, EventArgs e) { webView21.CoreWebView2.GoBack(); } private void forward_button_Click(object sender, EventArgs e) { webView21.CoreWebView2.GoForward(); } private void refresh_button_Click(object sender, EventArgs e) { webView21.CoreWebView2.Reload(); } private void stop_button_Click(object sender, EventArgs e) { webView21.CoreWebView2.Stop(); } private void search_button_Click(object sender, EventArgs e) { } private void webView21_NavigationStarting(object sender, CoreWebView2NavigationStartingEventArgs e) { } private void webView21_NavigationCompleted(object sender, CoreWebView2NavigationCompletedEventArgs e) { string currentUrl = webView21.Source.ToString(); if (!comboBox1.Items.Contains(currentUrl)) { comboBox1.Items.Add(currentUrl); } comboBox1.Text = currentUrl; } private void comboBox1_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { string url = comboBox1.Text; if (Uri.IsWellFormedUriString(url, UriKind.Absolute)) { webView21.CoreWebView2.Navigate(url); } else { MessageBox.Show("ÇëÊäÈëÓÐЧµÄÍøÖ·", "´íÎó", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } } }