2

我认为我们应该发起一个事件这是我发现的:

event OnButtonClicked ()EventArgs;
HTMLButtonClickEventArgs:EventArgs
{
String ButtonName;
}

我正在做一个网络浏览器控件,这是我为单击它的按钮编写的代码,但我想知道用户单击了哪个按钮:

    public delegate void ButtonPressedEventHandler(object sender, EventArgs e);
    public event ButtonPressedEventHandler ButtonPressed;

    void OnButtonPressed()
    {
        if (ButtonPressed != null)
            ButtonPressed(this, new EventArgs());            
    }
4

1 回答 1

2

我为你写了一个例子:试试这个:

  private void Form1_Load(object sender, EventArgs e)
        {

            webBrowser1.DocumentText = "<html><body><button id=\"btn1\" type=\"button\">Click Me!</button><button id=\"btn2\" type=\"button\">Click Me!</button></body></html>";
        }

调用点击事件:

     //Edited 
     bool First_Call = true;
    private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
    {
        if (First_Call)
        {
            webBrowser1.Document.Click += new HtmlElementEventHandler(Document_Click);
            First_Call = false;
        }
    }

当用户单击文档时获取活动元素但

        void Document_Click(object sender, HtmlElementEventArgs e)
        {
           // **Edited**
           //Check Element is Button 
           if (webBrowser1.Document.ActiveElement.TagName == "BUTTON")
           {
            MessageBox.Show(webBrowser1.Document.ActiveElement.Id);
           }
        }
于 2013-04-07T06:42:43.127 回答