如何使用c#在BHO中调用ihtmlelement button click中的c#方法

本文关键字:button click 中的 ihtmlelement 方法 何使用 BHO 调用 | 更新日期: 2023-09-27 18:17:51

我正在为IE编程BHO。我创建了一个按钮。我想在按钮click中调用一个方法。怎么称呼它

这里是我的代码:

htmlFormCollection = objDocument.getElementsByTagName("*");
                                if (htmlFormCollection.length > 0)
                                {
                                    foreach (IHTMLElement ihtmlCollectionClass in htmlFormCollection)
                                    {
                                        htmlElementsCollection = (IHTMLElementCollection)ihtmlCollectionClass.all;
                                        foreach (IHTMLElement ihtmlBtnAddClass in htmlElementsCollection)
                                        {
                                            if (ihtmlBtnAddClass.className == "n1tfz")
                                            {
                                                if (flagVal)
                                                {
                                                    IHTMLDOMNode divNode = (IHTMLDOMNode)ihtmlBtnAddClass;
                                                    var tbl = objDocument.createElement("table");
                                                    var tblBody = objDocument.createElement("tbody");
                                                    var tabr = objDocument.createElement("tr"); 
                                                    var tabd = objDocument.createElement("td");
                                                    var newDiv=objDocument.createElement("div"); 
                                                    newDiv.setAttribute("id","innerdiv11");
                                                    var Encryptbutton = objDocument.createElement("input");
                                                    Encryptbutton.setAttribute("type", "button");
                                                    Encryptbutton.setAttribute("value", "Encrypt");
                                                    Encryptbutton.setAttribute("id", "Encr1");
                                                    Encryptbutton.style.backgroundColor = "#4d90fe";
                                                    Encryptbutton.style.border = "#4787ed";
                                                    Encryptbutton.style.color = "White";
                                                    Encryptbutton.style.fontSize = "11px";
                                                    Encryptbutton.style.fontFamily = "arial,sans-serif";
                                                    Encryptbutton.style.width = "47pt";
                                                    //Encryptbutton.onclick = ComposeEncrypt();
                                                    //Encryptbutton.click();
                                                    IHTMLDOMNode newDivVal = (IHTMLDOMNode)newDiv;
                                                    IHTMLDOMNode tabdVal = (IHTMLDOMNode)tabd;
                                                    IHTMLDOMNode tabrVal = (IHTMLDOMNode)tabr;
                                                    IHTMLDOMNode tblBodyVal = (IHTMLDOMNode)tblBody;
                                                    IHTMLDOMNode tblVal = (IHTMLDOMNode)tbl;
                                                    newDivVal.appendChild((IHTMLDOMNode)Encryptbutton);
                                                    tabdVal.appendChild((IHTMLDOMNode)newDivVal);
                                                    tabrVal.appendChild((IHTMLDOMNode)tabdVal);
                                                    tblBodyVal.appendChild((IHTMLDOMNode)tabrVal);
                                                    tblVal.appendChild((IHTMLDOMNode)tblBodyVal);
                                                    IHTMLDOMNode divNode1 = (IHTMLDOMNode)ihtmlBtnAddClass;
                                                    IHTMLElement head = (IHTMLElement)((IHTMLElementCollection)objDocument.all.tags("head")).item(null, 0);
                                                    divNode.insertBefore((IHTMLDOMNode)Encryptbutton, divNode.firstChild);
                 //Encryptbutton.InvokeMember("click");
                                                    flagVal = false;
                                                }
                                            }
                                            if (!flagVal)
                                                break;
                                        }
                                    }
                                }

方法:

public void myfunc()
{
   Messgebox.show("hai");
}

我想在Encryptbutton点击事件中调用myfunc()。怎么称呼它

谢谢桑珠抱

如何使用c#在BHO中调用ihtmlelement button click中的c#方法

我明白了。

HTMLButtonElementEvents_Event htmlButtonEvent = Encryptbutton1 as HTMLButtonElementEvents_Event;
htmlButtonEvent.onclick += new HTMLButtonElementEvents_onclickEventHandler(ComposeEncrypt_onclick);

方法:

bool ComposeEncrypt_onclick()
{
MessageBox.show("hai");
}