C# WebBrowser Doubleclick inside splitcontainer.panel引发错误:System.Runtime.InteropServices.COMException HRESULT:0x800A025E
我在splitcontainer.panel中实现webbrowser控件时遇到了一些奇怪的问题。 抛出上述错误。我尝试了相同的编码,将其带到splitcontainer.panel之外;那一切都很好 加载网页时,我希望点击网页上的一个单词,然后,它应该选择双击的单词并显示在messagebox上 如果我们这里的任何专家能在这方面帮助我,我将不胜感激 这是我的示例编码:C# WebBrowser Doubleclick inside splitcontainer.panel引发错误:System.Runtime.InteropServices.COMException HRESULT:0x800A025E,c#,webbrowser-control,double-click,C#,Webbrowser Control,Double Click,我在splitcontainer.panel中实现webbrowser控件时遇到了一些奇怪的问题。 抛出上述错误。我尝试了相同的编码,将其带到splitcontainer.panel之外;那一切都很好 加载网页时,我希望点击网页上的一个单词,然后,它应该选择双击的单词并显示在messagebox上 如果我们这里的任何专家能在这方面帮助我,我将不胜感激 这是我的示例编码: PS:它在range1.select()处崩溃 更新:在进一步的测试中,我注意到,如果我不为webBrowser使用动态控制,
PS:它在range1.select()处崩溃 更新:在进一步的测试中,我注意到,如果我不为webBrowser使用动态控制,那么它也可以正常工作。 但动态选项卡、面板和webBrowser也是我的标准之一
public partial class Form1 : Form
{
public static string lbname;
public WebBrowser br1 = new WebBrowser();
public WebBrowser br2 = new WebBrowser();
public Form1()
{
InitializeComponent();
}
private void button1_Click_1(object sender, System.EventArgs e)
{
var tab = new TabPage("1");
tabControl1.Controls.Add(tab);
tabControl1.SelectedTab = tab;
tab.Select();
var pnl = new Panel();
tab.Controls.Add(pnl);
pnl.Controls.Add(br1);
Uri url1 = new Uri("http://www.google.com");
br1.Url = url1;
br1.DocumentCompleted += Browser1_DocumentCompleted;
}
private void Browser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
br1.Document.DetachEventHandler("ondblclick", Document_DoubleClick);
br1.Document.AttachEventHandler("ondblclick", Document_DoubleClick);
}
private void Document_DoubleClick(object sender, EventArgs e)
{
IHTMLDocument2 doc1 = br1.Document.DomDocument as IHTMLDocument2;
IHTMLSelectionObject currentSelection = doc1.selection;
if (currentSelection != null)
{
IHTMLTxtRange range1 = currentSelection.createRange() as IHTMLTxtRange;
if (range1 != null)
{
range1.expand("word");
range1.select();
MessageBox.Show("selected text" + range1.text);
}
}
}
=====
当然,我已经引用了mshtml和SHDocVw,因为除了splitcontainer.panel之外,它还在工作。在花了很多时间解决这个问题后,我决定取消splitcontainer,改用面板。不确定原因,但确定SplitContainer是问题所在,并通过使用面板设法解决