Search code examples
c#wpfselectionmshtml

How to get start and end posion of an mshtml.IHTMLSelectionObject?


here's my code :

var doc = webBrowser.Document as mshtml.HTMLDocument;
            if (doc != null)
            {
                var currentSelection = doc.selection;
                if (currentSelection != null)
                {
                    var selectionRange = currentSelection.createRange();

can I get the start and end position of selectionRange ?


Solution

  • public IHTMLTxtRange CurrentSelection
    {
        get
        {
            var htmlDocument = webBrowser.Document.DomDocument as IHTMLDocument2;
            IHTMLSelectionObject currentSelection = htmlDocument.selection;
            IHTMLTxtRange range = null;
            if (currentSelection != null)
            {
                range = currentSelection.createRange() as IHTMLTxtRange;
                //range.moveStart("wdCell",1);
                //range.moveEnd("wdCell",1);
            }
            return range;
        }
    }
    

    Range.MoveStart Method
    Programmatically Extend Ranges in Documents
    WdUnits Enumeration