Help with MSHTML and event firing

M

Mystery Man

I have successfully used MSHTML to develop an HTML editor in c#.

I now want to add extra functionality to trap function keys and do
additional processing. This proved to be more difficult than I had
hoped for.

After attempting to use IHTMLEditDesigner for this purpose I gave up
as I was unable to compile a class along the following lines:

public class HtmlEditor: System.Windows.Forms.UserControl,
IHTMLEditDesigner
{
public int PostEditorEventNotify(int eventId, IHTMLEventObj eventObj)
{

return HRESULT.S_OK;
}
public int PostHandleEvent (int eventId, IHTMLEventObj eventObj)
{

return HRESULT.S_OK;
}
public int PreHandleEvent(int eventId, IHTMLEventObj eventObj)
{

return HRESULT.S_OK;
}
public int TranslateAccelerator(int eventId, IHTMLEventObj eventObj)
{

return HRESULT.S_OK;
}
}

The compiler says that the 4 implementation methods are either static,
not public or have the wrong return type?? As far as I can deduce none
of these conditions is true???


I then tried the following:

HTMLDocumentEvents2_Event iEvent =
(HTMLDocumentEvents_Event)_document;
iEvent .onkeyup += new
HTMLDocumentEvents2_onkeyupEventHandler(KeyUpEventHandler);

private void KeyUpEventHandler(IHTMLEventObj e)
{
}

This is better in so far as it compiles and the event fires. However,
what I really want to do is only trap a very small subset of keys
pressed and ignore the rest. The event handler is simply gobbling up
all the keys. There was no way that I could see where I could easily
do this.

Eg, the sort of thing I was looking for was:

private bool KeyUpEventHandler(IHTMLEventObj e)
{
if (special case)
{
// Process
return true;
}
else
{
return false;
}
}

private void KeyUpEventHandler(IHTMLEventObj e)
{
if (special case)
{
// Process
e.Handled = true;
}
}

Therefore, how the heck can I use MSHTML to handle certain key presses
(and process the rest normally) using one of the above examples.

Your assistance would be very much appreciated.
 

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

Top