Windows 窗体
一组用于开发图形用户界面的 .NET Framework 托管库。
108 个问题
如何在winView2中goButton_Click导航? 不导航
private void goButton_Click(object sender, EventArgs e)
{
infoBox.Text = "goButton_Click BEFORE if";
if (webView != null && webView.CoreWebView2 != null)
{
webView.CoreWebView2.Navigate(addressBar.Text);
infoBox.Text = "goButton_Click AFTER if";
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Microsoft.Web.WebView2.Core;
namespace WinFormsGettngStarted
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.Resize += new System.EventHandler(this.Form_Resize);
webView = new Microsoft.Web.WebView2.WinForms.WebView2();
}
private void Form_Resize(object sender, EventArgs e)
{
webView.Size = this.ClientSize - new System.Drawing.Size(webView.Location);
webView.Height = this.ClientSize.Height - 70; // - new System.Drawing.Size(webView.Location);
webView.Width = this.ClientSize.Width - 20; // - new System.Drawing.Size(webView.Location);
sourceButton.Left = this.ClientSize.Width - sourceButton.Width - 20;
goButton.Left = this.ClientSize.Width - sourceButton.Width - goButton.Width - 40;
addressBar.Width = goButton.Left - addressBar.Left - 20;
infoBox.Text = webView.Width.ToString() + " " + webView.Height.ToString();
// infoBox.Text = "Form_Resize";
}
private void goButton_Click(object sender, EventArgs e)
{
infoBox.Text = "goButton_Click BEFORE if";
if (webView != null && webView.CoreWebView2 != null)
{
webView.CoreWebView2.Navigate(addressBar.Text);
infoBox.Text = "goButton_Click AFTER if";
}
}
private void addressBar_TextChanged(object sender, EventArgs e)
{
infoBox.Text = "addressBar_TextChanged";
}
private void refreshButton_Click(object sender, EventArgs e)
{
infoBox.Text = "refreshButton_Click";
}
private void homeButton_Click(object sender, EventArgs e)
{
infoBox.Text = "homeButton_Click";
}
private void infoBox_TextChanged(object sender, EventArgs e)
{
}
private void backButton_Click(object sender, EventArgs e)
{
infoBox.Text = "backButton_Click";
}
private void forwardButton_Click(object sender, EventArgs e)
{
infoBox.Text = "forwardButton_Click";
}
private void sourceButton_Click(object sender, EventArgs e)
{
infoBox.Text = "sourceButton_Click";
}
} // class Form1
} // namespace WinFormsGettngStarted
winforms 中的 Ste5
如果我删除“if 语句”并仅使用
复制
webView.CoreWebView2.Navigate(addressBar.Text);
我收到错误;System.NullReferenceException:“对象引用未设置为对象的实例。
我不明白为什么“webView.CoreWebView2”在“if语句” 中是好的,但在“Navigate语句”中却不行?
当我只使用这么多的“if 语句”进行编译时
SQL格式复制
if (webView.CoreWebView2 != null)
那么就没有错误了,但是导航在任何地方都没有导航。
Note:此问题总结整理于: 如何在winView2中导航goButton_Click?