首页 > 解决方案 > 当按钮从 Web 浏览器控件按下到 WPF 时生成事件

问题描述

我正在尝试制作一个在 WPF 中的 HTML(Web 浏览器)控件中按下按钮时生成事件(任何事件)的应用程序。到目前为止,我已经搜索并尝试了各种实现,但没有运气。我还附上了最近的尝试,我能够操纵 html 中的值,从 html 中读取,但在按下按钮时无法获得事件。

public void webBrowser_LoadCompleted()
    {

        HTMLDocument doc = (HTMLDocument)webBrowser.Document;
        IHTMLElementCollection theElementCollection = doc.getElementsByTagName("input");


        foreach (IHTMLElement curElement in theElementCollection)
        {  

            string uiAuto = curElement.getAttribute("fname").ToString();
            if (uiAuto == "")
            {
                curElement.setAttribute("value", "changed value!");
            }
            if (uiAuto == "...")
            {
                curElement.setAttribute("value", "...");
            }
            if (curElement.getAttribute("value") == "Login")
            {
                curElement.click();
            }
        }

    }

html

    <!DOCTYPE html>
<html>
<head>
    <title> Testing HTML </title>

</head>
<body>
<h1>Hi there!</h1>

  <button type="button">Click Me!</button> 

<input type="text" value="login" id="fname" name="fname"><br>

<h2>Bye!</h2>

</body>
</html>

我是 WPF 的新手,今天完成了这项任务。只想在我的 C# 应用程序中引发一个事件,当在 html 中按下按钮以及一些属性时,例如,文本框中的数据。

我还尝试编写一个 javascript 并在 webBrowser 中使用 invokeScript() ,但结果也不是很好。

期待一些帮助,谢谢。

标签: javascriptc#htmlwpfwebbrowser-control

解决方案


推荐阅读