【问题标题】:How to find INPUT element in wpf Webbrowser control如何在 wpf Webbrowser 控件中查找 INPUT 元素
【发布时间】:2017-09-07 13:09:58
【问题描述】:

我正在尝试构建一个应用程序,在该应用程序中,我在 webbrowser 控件的每个 INPUT 字段上都使用 tabtip。但我最近切换到 WPF 并在我使用的旧 WinForms 代码中 HtmlElement element = Browser.Document.GetElementFromPoint(e.ClientMousePosition)

在我的新代码中,我使用点击事件来确定我尝试打开 tabtip 的时间,但它只需要在点击的元素是 INPUT 字段时发生。我的代码:

public static void webBrowser1_LoadCompleted(object sender, NavigationEventArgs e, WebBrowser browser)
{
    mshtml.HTMLDocument doc;
    doc = (mshtml.HTMLDocument)browser.Document;
    mshtml.HTMLDocumentEvents2_Event iEvent;
    iEvent = (mshtml.HTMLDocumentEvents2_Event)doc;
    iEvent.onclick += new mshtml.HTMLDocumentEvents2_onclickEventHandler(ClickEventHandler);
}

这就是我要检查点击的元素是否是输入的地方:

private static bool ClickEventHandler(mshtml.IHTMLEventObj e)
{
    MessageBox.Show("Item Clicked"); //if(HtmlElement == INPUT) like scenario here
    return true;
}

我使用了this 源,但我很难理解他们的话,因为我正在尝试使用 xaml 和 c# 处理所有内容。

【问题讨论】:

    标签: c# wpf input webbrowser-control


    【解决方案1】:

    试试这个:

    private static bool ClickEventHandler(mshtml.IHTMLEventObj e)
    {
        mshtml.IHTMLInputElement inputElement = e.srcElement as mshtml.IHTMLInputElement;
        if (inputElement != null)
        {
            MessageBox.Show("<input> clicked");
        }
        return true;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-22
      • 1970-01-01
      • 2013-06-20
      • 2011-09-30
      相关资源
      最近更新 更多