123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- 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);
- }
- }
- }
- }
- }
|