C#阻止识别子元素时触发父元素

Alan_95 2019-08-19 11:15:52
在C#代码中嵌套了一层循环后,在识别子元素时,父元素同步被识别,试问如何消除父元素的识别,之让其识别循环中的子层。

循环的代码如下:
int count = webBrowser1.Document.Window.Frames.Count;
for (int i = 0; i < count; i++)
{
HtmlDocument tempElement1 = webBrowser1.Document.Window.Frames[i].Document;
tempElement1.MouseOver += TempElement_MouseOver;
tempElement1.MouseLeave += TempElement_MouseLeave;

int count1 = tempElement1.Window.Frames.Count;
for(int j = 0;j < count1; j++)
{

HtmlDocument tempElement2 = tempElement1.Window.Frames[j].Document;
tempElement2.MouseOver += TempElement_MouseOver;
tempElement2.MouseLeave += TempElement_MouseLeave;
}

}

测试时如下,子层和父层都有红框:求解决
...全文
93 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
正怒月神 2019-08-20
  • 打赏
  • 举报
回复
那你外层,绑定一个别的事件。 别两个绑一样的额
Alan_95 2019-08-19
  • 打赏
  • 举报
回复
是这样的,如果只保留如下代码,可以实现下图的抓取 int count = webBrowser1.Document.Window.Frames.Count; for (int i = 0; i < count; i++) { HtmlDocument tempElement1 = webBrowser1.Document.Window.Frames[i].Document; tempElement1.MouseOver += TempElement_MouseOver; tempElement1.MouseLeave += TempElement_MouseLeave; } 如上所示,抓取不到二图的百度框,当再加入一层循环后(如下代码)可以抓取到百度框,但是就出现了之前那个多层红框的问题,求如何解决,可能之前的表述不太清楚。 int count1 = tempElement1.Window.Frames.Count; for(int j = 0;j < count1; j++) { HtmlDocument tempElement2 = tempElement1.Window.Frames[j].Document; tempElement2.MouseOver += TempElement_MouseOver; tempElement2.MouseLeave += TempElement_MouseLeave; }
正怒月神 2019-08-19
  • 打赏
  • 举报
回复
那 tempElement1.MouseOver += TempElement_MouseOver; tempElement1.MouseLeave += TempElement_MouseLeave; 去掉不就好了吗?

110,536

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧