Click here to Skip to main content
15,886,110 members
Home / Discussions / C#
   

C#

 
GeneralRe: Newline in Label Text Pin
Okeno Palmer5-May-04 14:51
Okeno Palmer5-May-04 14:51 
GeneralMore of column headers filters in custom lisview Pin
machocr5-May-04 10:58
machocr5-May-04 10:58 
GeneralRe: More of column headers filters in custom lisview Pin
Heath Stewart5-May-04 14:02
protectorHeath Stewart5-May-04 14:02 
Generalfish eye images converter Pin
doph5-May-04 8:34
doph5-May-04 8:34 
GeneralStrange TypeLoadException Pin
Broken God5-May-04 5:59
Broken God5-May-04 5:59 
GeneralRe: Strange TypeLoadException Pin
leppie5-May-04 6:52
leppie5-May-04 6:52 
GeneralRe: Strange TypeLoadException Pin
Anonymous5-May-04 7:47
Anonymous5-May-04 7:47 
GeneralRemoving event listeners on IHTMLDocument2 objects Pin
agking5-May-04 5:56
agking5-May-04 5:56 
I am hosting a WebBrowser control, and have a reference to the association document property (IHTMLDocument2 interface). Per Microsoft's guidelines, I have attached events as follows:

private void AttachListeners(IHTMLDocument2 Document) {
HTMLDocumentEvents2_Event iEvent = (HTMLDocumentEvents2_Event)Document;
iEvent.onmouseover += new HTMLDocumentEvents2_onmouseoverEventHandler(Element_onmouseover);
iEvent.onmouseout += new HTMLDocumentEvents2_onmouseoutEventHandler(Element_onmouseout);
}

I have another method, to remove the event listeners:

private void DetachListeners(IHTMLDocument2 Document) {
HTMLDocumentEvents2_Event iEvent = (HTMLDocumentEvents2_Event)Document;
iEvent.onmouseover -= new HTMLDocumentEvents2_onmouseoverEventHandler(Element_onmouseover);
iEvent.onmouseout -= new HTMLDocumentEvents2_onmouseoutEventHandler(Element_onmouseout);
}

My problem is that when I remove the listeners, it actually causes them to fire twice! If I try to call DetachListeners a second time, I get an error "object reference not set to an instance of an object" (I would expect some sort of error because I'm theoretically removing an event that has already been removed).

My guess is that there is a bug here in the interop stuff, where the "-=" operator is removing the event from the .net view of the world but adding it again in the COM level.

Anyone had this problem before, or know where to look?

Anthony King
GeneralDLL Help Pin
goldoche5-May-04 5:54
goldoche5-May-04 5:54 
GeneralRe: DLL Help Pin
Heath Stewart5-May-04 6:59
protectorHeath Stewart5-May-04 6:59 
GeneralXmlDocument, SOAP& Namespaces Pin
MrEyes5-May-04 5:40
MrEyes5-May-04 5:40 
GeneralRe: XmlDocument, SOAP& Namespaces Pin
Heath Stewart5-May-04 5:44
protectorHeath Stewart5-May-04 5:44 
GeneralRe: XmlDocument, SOAP& Namespaces Pin
MrEyes5-May-04 5:58
MrEyes5-May-04 5:58 
GeneralRe: XmlDocument, SOAP& Namespaces Pin
Heath Stewart5-May-04 7:10
protectorHeath Stewart5-May-04 7:10 
GeneraldataGridTextBoxColumn textBox Pin
blankg5-May-04 5:16
blankg5-May-04 5:16 
Generalc# Listbox help Pin
John Baird5-May-04 4:48
John Baird5-May-04 4:48 
GeneralRe: c# Listbox help Pin
Heath Stewart5-May-04 4:59
protectorHeath Stewart5-May-04 4:59 
GeneralRe: c# Listbox help Pin
John Baird5-May-04 9:21
John Baird5-May-04 9:21 
GeneralRe: c# Listbox help Pin
Heath Stewart5-May-04 9:31
protectorHeath Stewart5-May-04 9:31 
GeneralCreating & Using DLL's Pin
Lakshmikanthan5-May-04 4:42
Lakshmikanthan5-May-04 4:42 
GeneralRe: Creating & Using DLL's Pin
Heath Stewart5-May-04 4:55
protectorHeath Stewart5-May-04 4:55 
GeneralDiffgrams and Web Services Pin
MrJJKoolJ5-May-04 3:51
MrJJKoolJ5-May-04 3:51 
GeneralRe: Diffgrams and Web Services Pin
Heath Stewart5-May-04 4:13
protectorHeath Stewart5-May-04 4:13 
GeneralRe: Diffgrams and Web Services Pin
MrJJKoolJ5-May-04 5:08
MrJJKoolJ5-May-04 5:08 
GeneralRe: Diffgrams and Web Services Pin
Heath Stewart5-May-04 5:16
protectorHeath Stewart5-May-04 5:16 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.