首页 新闻 搜索 专区 学院

html编辑器光标位置自动回复的问题

0
[已关闭问题]

其中wb1是一个webbrowser控件

代码如下,可为什么光标位置无法恢复呢?

        private void toolStripButton2_Click(object sender, EventArgs e)
        {
            if (wb1.Document != null)
            {
                IHTMLDocument2 doc = wb1.Document.DomDocument as IHTMLDocument2;
                if (doc != null)
                {
                    IHTMLTxtRange range =  doc.selection.createRange() as IHTMLTxtRange;
                    if (range != null) _bookmark =  range.getBookmark();
                }
            }
            _text = wb1.DocumentText;
            wb1.DocumentText = "";
        }

        private void toolStripButton3_Click(object sender, EventArgs e)
        {
            if(!string.IsNullOrEmpty(_bookmark))
            {
                wb1.DocumentText = _text;
                if (wb1.Document != null)
                {
                    IHTMLDocument2 doc = wb1.Document.DomDocument as IHTMLDocument2;
                    if (doc != null)
                    {
                        IHTMLBodyElement bodyElement = doc.body as IHTMLBodyElement;
                        if (bodyElement != null)
                        {
                            IHTMLTxtRange range = bodyElement.createTextRange();
                            range.moveToBookmark(_bookmark);
                            range.select();
                        }
                    }
                }
                _bookmark = string.Empty;
                _text = "";
            }
        }

参考链接:

设置光标位置的问题:SetDocumentHTML(html) 之后, SetCaretPos(curpos) 为何失效?
http://topic.csdn.net/t/20050729/22/4177529.html
HTML可视化编辑器中IE丢失光标位置的问题。
http://hi.baidu.com/jindw/blog/item/8c3e928ba1f04dd0fc1f10d2.html

蛙蛙王子的主页 蛙蛙王子 | 菜鸟二级 | 园豆:265
提问于:2008-10-14 13:12
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册