Frage

I'm working with the WebBrowser control, using the DesignMode function for editing HTML. I'm using the MSHTML interfaces in order to look at and modify the DOM.

Take for example an input text box - I can attach an event sink using the connection point, or add a custom rendering behavior, but when I move this input box to another part of the document, I lose both the connection point hook, and the behavior that was added.

Is there any kind of event I can hook up to in which I can connect the event sink and re-add the behavior?

War es hilfreich?

Lösung

I couldn't find any events to hook on to for when elements are deleted or created by the control, I did find an event that will fire when any changes are made (including by the control itself): IHTMLChangeSink

This interface has one method "Notify()" which fires whenever the document changes.

Hooking up the event to the class implementing this interface:

        var markupContainer = _document as IMarkupContainer2;
        if(markupContainer != null)
        {
            uint tmpCookie = 0;
            markupContainer.RegisterForDirtyRange(this, out tmpCookie);
            _changeSinkCookie = tmpCookie;
        }

I keep a list of elements that are in the document, and then diff when this event fires to tell if any elements were added or removed.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top