【发布时间】:2010-09-19 15:35:16
【问题描述】:
我正在为 IE(6+) 编写工具栏。我使用了来自
的各种示例条codeproject.com (http://www.codeproject.com/KB/dotnet/IE_toolbar.aspx),并且有一个可以工作的工具栏,注册注销等。我想要工具栏做的是在用户的鼠标移到该 div 上时突出显示 html 页面中的 div。到目前为止,突出显示代码有效,但我想在工具栏上的标签中显示 div 的名称(如果存在)(随着鼠标移动等而变化)。
我这辈子都做不到,试图调试它是一场噩梦。由于程序集托管在 IE 中,我怀疑我通过尝试从未创建该控件的线程更新标签上的文本而导致异常(在 IE 中),但由于该异常发生在 IE 中,我没看到。
解决方案是尝试使用 Invoke 以线程安全的方式更新控件吗?如果有怎么办?
这里是事件代码:
private void Explorer_MouseOverEvent(mshtml.IHTMLEventObj e)
{
mshtml.IHTMLDocument2 doc = this.Explorer.Document as IHTMLDocument2;
element = doc.elementFromPoint(e.clientX, e.clientY);
if (element.tagName.Equals("DIV", StringComparison.InvariantCultureIgnoreCase))
{
element.style.border = "thin solid blue;";
if (element.className != null)
{
UpdateToolstrip(element.className);
}
}
e.returnValue = false;
}
这是对工具栏的线程安全更新的尝试:
delegate void UpdateToolstripDelegate(string text);
public void UpdateToolstrip(string text)
{
if (this.toolStripLabel1.InvokeRequired == false)
{
this.toolStripLabel1.Text = text;
}
else
{
this.Invoke(new UpdateToolstripDelegate(UpdateToolstrip), new object[] { text });
}
}
非常感谢任何建议。
【问题讨论】:
标签: c# internet-explorer com user-interface toolbar