这是我的代码:

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


如何获取selectionRange的开始和结束位置?

最佳答案

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

关于c# - 如何获得mshtml.IHTMLSelectionObject的开始和结束位置?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/25326907/

10-09 19:58