In MSHTML interface HTMLDocumentEvents4 should contain around 30 events (as per msdn page http://msdn.microsoft.com/en-us/library/ff976251(v=vs.85).aspx#events) but only onmssitemodejumplistitemremoved and onmsthumbnailclick are available I want to access other events..especially change event.. How to access those other events
using System.Runtime.InteropServices;
namespace MSHTML
{
[ComVisible(false)]
[TypeLibType(TypeLibTypeFlags.FHidden)]
public interface HTMLDocumentEvents4_Event
{
event HTMLDocumentEvents4_onmssitemodejumplistitemremovedEventHandler onmssitemodejumplistitemremoved;
event HTMLDocumentEvents4_onmsthumbnailclickEventHandler onmsthumbnailclick;
}
}
In my code I tried to access like following but it is not working(listener not assigned)
//Event handler class
public delegate void DHTMLEvent(IHTMLEventObj e);
[ComVisible(true)]
public class DHTMLEventHandler
{
public DHTMLEvent Handler;
HTMLDocument Document;
public DHTMLEventHandler(HTMLDocument doc)
{
this.Document = doc;
}
[DispId(0)]
public void Call()
{
Handler(Document.parentWindow.@event);
}
}
//My code
HTMLDocumentEvents2_Event Events = (HTMLDocumentEvents2_Event)document;
Events.onclick += new HTMLDocumentEvents2_onclickEventHandler(Events_onclick);//working
HTMLDocumentEvents4_Event Events2 = (HTMLDocumentEvents4_Event)document;
// Events2.change ->Not availabe so as a workaround I did the below but that is also not // working
DHTMLEventHandler onchangeHandler = new DHTMLEventHandler(document);
onchangeHandler.Handler += new DHTMLEvent(Events_onchange);
document.attachEvent("onchange", onchangeHandler); //Not working
document.onchange = onchangeHandler; //Not Working
private void Events_onchange(IHTMLEventObj e)
{
//I want to do my operation here but this is not called as listener is not assigned
}
private Boolean Events_onclick(IHTMLEventObj e)
{
//working perfectly
}
So I want to listen the onchange event either by custom methods or by using HTMLDocumentEvents4 interface's hidden event..Help me
I got a workaround for how to attach event listeners to element
1.create HTMLHandlerClass for attaching eventhandlers to element
2.get all the elements from document or the elements for which you want to attach listener
3.cast the element as IHTMLElement2
4.attach the eventlistener by calling element.attachEvent
Step 1
Step 2
Here i'm getting all the input elements as i want to attach onchange event listener