Form1.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. using Microsoft.Web.WebView2.WinForms;
  2. using Microsoft.Web.WebView2.Core;
  3. namespace EdgeVoyager
  4. {
  5. public partial class Form1 : Form
  6. {
  7. public Form1()
  8. {
  9. InitializeComponent();
  10. InitializeAsync();
  11. }
  12. async void InitializeAsync()
  13. {
  14. await webView21.EnsureCoreWebView2Async(null);
  15. webView21.CoreWebView2.Navigate("https://cn.bing.com/?mkt=zh-CN");
  16. }
  17. private void back_button_Click(object sender, EventArgs e)
  18. {
  19. webView21.CoreWebView2.GoBack();
  20. }
  21. private void forward_button_Click(object sender, EventArgs e)
  22. {
  23. webView21.CoreWebView2.GoForward();
  24. }
  25. private void refresh_button_Click(object sender, EventArgs e)
  26. {
  27. webView21.CoreWebView2.Reload();
  28. }
  29. private void stop_button_Click(object sender, EventArgs e)
  30. {
  31. webView21.CoreWebView2.Stop();
  32. }
  33. private void search_button_Click(object sender, EventArgs e)
  34. {
  35. }
  36. private void webView21_NavigationStarting(object sender, CoreWebView2NavigationStartingEventArgs e)
  37. {
  38. }
  39. private void webView21_NavigationCompleted(object sender, CoreWebView2NavigationCompletedEventArgs e)
  40. {
  41. string currentUrl = webView21.Source.ToString();
  42. if (!comboBox1.Items.Contains(currentUrl))
  43. {
  44. comboBox1.Items.Add(currentUrl);
  45. }
  46. comboBox1.Text = currentUrl;
  47. }
  48. private void comboBox1_KeyDown(object sender, KeyEventArgs e)
  49. {
  50. if (e.KeyCode == Keys.Enter)
  51. {
  52. string url = comboBox1.Text;
  53. if (Uri.IsWellFormedUriString(url, UriKind.Absolute))
  54. {
  55. webView21.CoreWebView2.Navigate(url);
  56. }
  57. else
  58. {
  59. MessageBox.Show("ÇëÊäÈëÓÐЧµÄÍøÖ·", "´íÎó", MessageBoxButtons.OK, MessageBoxIcon.Error);
  60. }
  61. }
  62. }
  63. }
  64. }