This is the discussion forum for the HtmlEditor. See also the
HtmlEditor home page, where you can download the control, and the
Documentation Wiki, a collaborative project for documenting the control.
Re: Key Press Events
Posted by:
Tim Anderson (---.server.ntl.com)
Date: Tuesday, 19-Nov-2002, 15:47:33
Off the top of my head, no, I don't know.
Observations:
UpdateUI gets called on keypresses, when the control has the focus. You can verify this by clicking on the control with the mouse, then pressing keys. If you have a Debug.Writeline in UpdateUI, you can see the method gets called.
TranslateAccelerator never seems to get called, yet I reckon it should be.
PreProcessMessage always gets called. This is an override of one of Control's methods. The message argument tells you which key was pressed. This is a good bet if you just want to trap certain keypresses.
You can also attach event handlers to specific HTML elements ... but this is where things get strange. For example, I can load a document which includes an input element of type Button, and then attach an event handler to the button by getting its HTMLInputTextElementEvents2_Event interface. However, when I do this, the button no longer appears to depress when clicked (although the event does fire). This type of behaviour makes it really hard to create a DHTML interface for an app. I believe similar problems crop up if you try to do this with the WebBrowser control. I've raised this a couple of times with Microsoft but not gotten an answer as yet (still hopeful!). However, it is currently the same in Everett beta.
Tim
Re: Key Press Events
Posted by:
Steven Wood (---.cableinet.co.uk)
Date: Monday, 25-Nov-2002, 16:35:48
I too have had the same problems attaching events, although you can do it rather effectively using some sample code posted by Chris Paldino. I've also been experimenting with the GetExternal call and this seems to work well. All in all this makes creating a DHTML interface for an app possible.
The following code works both in the HtmlEditor and WebBrowser control, although I still can't get the key presses to work for the HtmlEditor.
Shall I add the following code to the HtmlEditor control with some plumbing to handle the event?
//Attach the events
m_htmldoc.onkeydown = this;
m_htmldoc.onclick = this;
[DispId(0)]
public void DefaultMethod()
{
// Get the event.
mshtml.IHTMLEventObj pobjEvent = ((mshtml.IHTMLDocument2)
axWebBrowser1.Document).parentWindow.@event;
// Display information about the event.
Console.WriteLine("Event Info\nType: " + pobjEvent.type + "\nElement: " +
pobjEvent.srcElement );
// That's all folks.
return;
}
Re: Key Press Events
Posted by:
Steven Wood (---.cableinet.co.uk)
Date: Wednesday, 11-Dec-2002, 11:33:14
Cheers Tim.
I notice that most of the key presses work, as commented in the code, great! Unfortunately the up and down keys do not, which is what led me to the conclusion that none of the keys worked. If you try the up and down arrows you'll see that they don't get passed as events, instead they seem to be controlling the scroll bars which is not normal behaviour(I think) if the html doc has focus. Still a problem, I'll get back to you if I find a solution.
Thanks,
Steven