C# Programming
09-18-2009, 11:31 PM
Hi all, I have some issues on Registering event, If you have any idea on my implementation please help me …
private SHDocVw.InternetExplorer browser;
HTMLDocument document;
HTMLDocumentEvents2_Event DocEvents;
This Event Fires well, when ever I click on any link the event is fired no issue on that. But when I click on the Text box the focus losts.
browser = (SHDocVw.InternetExplorer)pDisp;
DocEvents = (mshtml.HTMLDocumentEvents2_Event)document;
DocEvents.onclick += new HTMLDocumentEvents2_onclickEventHandler(DocEvents_onclick);
To over come this issues I have just implemented from one of the articles like bellow
// The delegate:
public delegate void DHTMLEvent(IHTMLEventObj e);
///
/// Generic Event handler for HTML DOM objects.
/// Handles a basic event object which receives an IHTMLEventObj which
/// applies to all document events raised.
///
[ComVisible(false)]
public class DHTMLEventHandler
{
public DHTMLEvent Handler;
mshtml.HTMLDocument Document;
public DHTMLEventHandler(mshtml. HTMLDocument doc)
{
this.Document = doc;
}
[DispId(0)]
public void Call()
{
Handler(Document.parent********@event);
}
}
browser = (SHDocVw.InternetExplorer)pDisp;
mshtml.HTMLDocument doc = (mshtml.HTMLDocument)browser.Document;
DHTMLEventHandler Handler = new DHTMLEventHandler(doc);
Handler.Handler += new DHTMLEvent(this.myCallback);
doc.onclick = Handler;
but it shows the bello error.
Ambiguity between 'mshtml.DispHTMLDocument.onclick' and 'mshtml.HTMLDocumentEvents_Event.onclick
So I have changed from mshtml.HTMLDocument to mshtml.DispHTMLDocument
Now there is no compilation error but while excecuting it shows the bellow error
System.NotImplementedException , NotImplemented “\r\n”
Somewhat I got the information that we have to use mshtml. IHTMLDocument2 So I have used as bellow
public delegate void DHTMLEvent(mshtml.IHTMLEventObj e);
[ComVisible(true)]
public class DHTMLEventHandler
{
public DHTMLEvent Handler;
mshtml.IHTMLDocument2 Document;
public DHTMLEventHandler(mshtml.IHTMLDocument2 doc)
{
this.Document = doc;
}
[DispId(0)]
public void Call()
{
Handler(Document.parent********@event);
}
}
DispHTMLDocument dispDoc = (mshtml.DispHTMLDocument)browser.Document;
mshtml.IHTMLDocument2 doc = (mshtml.IHTMLDocument2)browser.Document;
DHTMLEventHandler Handler = new DHTMLEventHandler(doc);
Handler.Handler += new DHTMLEvent(this.myCallback);
dispDoc.onclick = Handler;
public void myCallback(IHTMLEventObj evo)
{
// Do useful stuff...
}
Now this runs good, but no event is fired while I click on the browser
If some one has any observation on that please guide me how to go with this. I am able to use IHTMLElementCollection and add events for each and every IHTMLElement But I am not interest in loop through all the elements and register events for each and every elements, rather want to regisert an event for a Document and from that I want to identify which element is clicked.
There are type of approaches.W3C Document Object Event Model.and Microsoft Event Object Model.
I think we can achieve the issues using Event Register and Bubbling
I know little bit on concept wise but not able to implement
If some one helps me … then it will be helpful for many…
Plese free to post your comments on that
Thanks for every one (those who involves in it)
private SHDocVw.InternetExplorer browser;
HTMLDocument document;
HTMLDocumentEvents2_Event DocEvents;
This Event Fires well, when ever I click on any link the event is fired no issue on that. But when I click on the Text box the focus losts.
browser = (SHDocVw.InternetExplorer)pDisp;
DocEvents = (mshtml.HTMLDocumentEvents2_Event)document;
DocEvents.onclick += new HTMLDocumentEvents2_onclickEventHandler(DocEvents_onclick);
To over come this issues I have just implemented from one of the articles like bellow
// The delegate:
public delegate void DHTMLEvent(IHTMLEventObj e);
///
/// Generic Event handler for HTML DOM objects.
/// Handles a basic event object which receives an IHTMLEventObj which
/// applies to all document events raised.
///
[ComVisible(false)]
public class DHTMLEventHandler
{
public DHTMLEvent Handler;
mshtml.HTMLDocument Document;
public DHTMLEventHandler(mshtml. HTMLDocument doc)
{
this.Document = doc;
}
[DispId(0)]
public void Call()
{
Handler(Document.parent********@event);
}
}
browser = (SHDocVw.InternetExplorer)pDisp;
mshtml.HTMLDocument doc = (mshtml.HTMLDocument)browser.Document;
DHTMLEventHandler Handler = new DHTMLEventHandler(doc);
Handler.Handler += new DHTMLEvent(this.myCallback);
doc.onclick = Handler;
but it shows the bello error.
Ambiguity between 'mshtml.DispHTMLDocument.onclick' and 'mshtml.HTMLDocumentEvents_Event.onclick
So I have changed from mshtml.HTMLDocument to mshtml.DispHTMLDocument
Now there is no compilation error but while excecuting it shows the bellow error
System.NotImplementedException , NotImplemented “\r\n”
Somewhat I got the information that we have to use mshtml. IHTMLDocument2 So I have used as bellow
public delegate void DHTMLEvent(mshtml.IHTMLEventObj e);
[ComVisible(true)]
public class DHTMLEventHandler
{
public DHTMLEvent Handler;
mshtml.IHTMLDocument2 Document;
public DHTMLEventHandler(mshtml.IHTMLDocument2 doc)
{
this.Document = doc;
}
[DispId(0)]
public void Call()
{
Handler(Document.parent********@event);
}
}
DispHTMLDocument dispDoc = (mshtml.DispHTMLDocument)browser.Document;
mshtml.IHTMLDocument2 doc = (mshtml.IHTMLDocument2)browser.Document;
DHTMLEventHandler Handler = new DHTMLEventHandler(doc);
Handler.Handler += new DHTMLEvent(this.myCallback);
dispDoc.onclick = Handler;
public void myCallback(IHTMLEventObj evo)
{
// Do useful stuff...
}
Now this runs good, but no event is fired while I click on the browser
If some one has any observation on that please guide me how to go with this. I am able to use IHTMLElementCollection and add events for each and every IHTMLElement But I am not interest in loop through all the elements and register events for each and every elements, rather want to regisert an event for a Document and from that I want to identify which element is clicked.
There are type of approaches.W3C Document Object Event Model.and Microsoft Event Object Model.
I think we can achieve the issues using Event Register and Bubbling
I know little bit on concept wise but not able to implement
If some one helps me … then it will be helpful for many…
Plese free to post your comments on that
Thanks for every one (those who involves in it)