MSHTML event weirdness

P

Peter Wone

In the excerpt below, the onclick event fires my handler, but the onkeypress
event does not. I've got a WebBrowser control on a form and I'm trying to
bind element events. I can bind weird events like onmouseenter and
onmousemove (omitted for brevity, they require a different method signature)
but according to MSDN the two events illustrated in the following code
should have identical signatures. One works and the other does not. I would
just love it if someone could put me out of my misery and explain why. For
extra credit you could also explain why the onchange event shows the same
problem. As a matter of interest, MSDN says onchange is a void function but
the typelib requires a bool function.

private void PaneMain_DocumentComplete(object sender,
AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEvent e) {

DocMain = (HTMLDocument)PaneMain.Document;

DocTools = (HTMLDocument)PaneTools.Document;

IHTMLElement theBody = (IHTMLElement)DocMain.body;

theBody.innerHTML = "<button id='B1'>New style</button> <a id='B2'
href=''>Anchor</a><FORM ACTION='http://localhost/' METHOD='POST'><INPUT
ID='W1' VALUE='BLAH BLAH'></FORM>";

IHTMLElementCollection cAll = (IHTMLElementCollection)DocMain.all;

HTMLInputTextElement W1 = (HTMLInputTextElement)cAll.item("W1",0);

((HTMLInputTextElementEvents2_Event)W1).onclick += new
HTMLInputTextElementEvents2_onclickEventHandler(this.HandlerClick);

((HTMLInputTextElementEvents2_Event)W1).onkeypress += new
HTMLInputTextElementEvents2_onkeypressEventHandler(this.HandlerKeypress);

}

private bool HandlerClick(IHTMLEventObj e) {

IHTMLElement Element = e.srcElement;

Console.Write("Click:");

Console.WriteLine(Element.tagName);

return true;

}

private bool HandlerKeypress(IHTMLEventObj e) {

HTMLInputTextElement Element = (HTMLInputTextElement)e.srcElement;

Console.Write("KeyPress:");

Console.WriteLine(Element.value);

return true;

}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Events in class IEDriver 0
Asp.net Important Topics. 0

Top