WPF/WebBrowser - 没有重载匹配委托
WPF / WebBrowser - No overload matches delegate
我试图在网络浏览器 (WPF) 中突出显示一些文本。不幸的是,我无法摆脱以下错误:
'Browser_LoadCompleted' 没有重载匹配委托 'LoadCompletedEventHandler'
这一行有红色下划线 -> StringBuilder html = new StringBuilder(doc2.body.outerHTML);
感谢任何帮助。谢谢。
using mshtml;
using System;
using System.Text;
using System.Windows.Controls;
using System.Windows.Navigation;
namespace LSS_doc.Views
{
/// <summary>
/// Interaction logic for ViewTabView.xaml
/// </summary>
public partial class ViewTabView : UserControl
{
public ViewTabView()
{
InitializeComponent();
WebBrowser browser = new WebBrowser();
browser.LoadCompleted += Browser_LoadCompleted;
}
public void Browser_LoadCompleted(object sender, LoadCompletedEventHandler e)
{
IHTMLDocument2 doc2 = browser.Document as IHTMLDocument2;
StringBuilder html = new StringBuilder(doc2.body.outerHTML);
var words = new[] { "word", "word2" };
foreach (String key in words)
{
String substitution = "<span style='background-color: rgb(255, 255, 0);'>" + key + "</span>";
html.Replace(key, substitution);
}
doc2.body.innerHTML = html.ToString();
}
}
}
您的事件处理程序定义错误。
查看MSDN LoadCompletedEventHandler which is what the WebBrowser Control's LoadCompleted事件使用,需要使用NavigationEventArgs
。
public void Browser_LoadCompleted(object sender, NavigationEventArgs e)
{
...
}
关于你关于 StringBuilder
的红线,我恳请你实际查看错误,查看 constructor options,并验证你传递的内容。
我试图在网络浏览器 (WPF) 中突出显示一些文本。不幸的是,我无法摆脱以下错误:
'Browser_LoadCompleted' 没有重载匹配委托 'LoadCompletedEventHandler'
这一行有红色下划线 -> StringBuilder html = new StringBuilder(doc2.body.outerHTML);
感谢任何帮助。谢谢。
using mshtml;
using System;
using System.Text;
using System.Windows.Controls;
using System.Windows.Navigation;
namespace LSS_doc.Views
{
/// <summary>
/// Interaction logic for ViewTabView.xaml
/// </summary>
public partial class ViewTabView : UserControl
{
public ViewTabView()
{
InitializeComponent();
WebBrowser browser = new WebBrowser();
browser.LoadCompleted += Browser_LoadCompleted;
}
public void Browser_LoadCompleted(object sender, LoadCompletedEventHandler e)
{
IHTMLDocument2 doc2 = browser.Document as IHTMLDocument2;
StringBuilder html = new StringBuilder(doc2.body.outerHTML);
var words = new[] { "word", "word2" };
foreach (String key in words)
{
String substitution = "<span style='background-color: rgb(255, 255, 0);'>" + key + "</span>";
html.Replace(key, substitution);
}
doc2.body.innerHTML = html.ToString();
}
}
}
您的事件处理程序定义错误。
查看MSDN LoadCompletedEventHandler which is what the WebBrowser Control's LoadCompleted事件使用,需要使用NavigationEventArgs
。
public void Browser_LoadCompleted(object sender, NavigationEventArgs e)
{
...
}
关于你关于 StringBuilder
的红线,我恳请你实际查看错误,查看 constructor options,并验证你传递的内容。