Monitoring Changes to the Document

At the moment the HTMLEditor does not support the idea of a 'Dirty' flag. If you wish to use this functionality then you have to implement it yourself. The technique involved is a little abstruse, but straightforward enough to implement. The steps are as follows:

  1. Cast the Document property to an IMarkupContainer2 interface
  2. Declare a class that implements IHTMLChangeSink
  3. Declare a variable of type IHTMLChangeLog and bind it to the IMarkupContainer2

This can be done at the form level or any other encapsulating class

Private mobjChangeLog As mshtml.IHTMLChangeLog
Private DocumentMarkupCtr2 As mshtml.IMarkupContainer2
Private WithEvents MyChangeMonitor as New ChangeMonitor

ChangeMonitor should implement the IHTMLChangeSink interface:

<Runtime.InteropServices.ComVisible(True)> _
Public Class ChangeMonitor
    Implements mshtml.IHTMLChangeSink
    Public Event ContentChanged()
    Public Dirty As Boolean
    Public Sub Notify() Implements mshtml.IHTMLChangeSink.Notify
        Dirty = True
        RaiseEvent ContentChanged()
    End Sub
End Class

Then, when the ReadyStateChange event is raised by the HTMLEditor, bind the classes:

DocumentMarkupCtr2 = CType(HTMLEditor.Document, mshtml.IMarkupContainer2)
With DocumentMarkupCtr2
    .CreateChangeLog(MyChangeMonitor, mobjChangeLog, 1, 1)
End With

The IHTMLChangeSink.Notify method is then called on MyChangeMonitor to inform the class of changes to the top level DocumentMarkupCtr2. You can set a flag in the body of this method, or perform other appropriate actions.

dirty_flag.txt · Last modified: 2007/07/26 08:52 (external edit)
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki