使用WebBrowser与msHtml开发WinForms下的HtmlEditor控件
引用COM控件WebBrowser
引用msHtml。
BS,還在用vs2003。要是使用2005就不需要使用COM控件。
?
初始化:
With Me.AxWebBrowser1
???? .Navigate("about:blank")
???? doc = CType(.Document, mshtml.IHTMLDocument2)
???? doc.designMode = "on"
End With
bs:designMode居然是一個隱藏屬性,找了半天都沒有發(fā)現(xiàn),還以為資料有誤呢。
常用命令:
Case "加粗"
??????????? doc.execCommand("Bold", False, Nothing)
??????? Case "傾斜"
??????????? doc.execCommand("Italic", False, Nothing)
??????? Case "下劃線"
??????????? doc.execCommand("Underline", False, Nothing)
??????? Case "序列"
??????????? doc.execCommand("InsertOrderedList", False, Nothing)
??????? Case "園點"
??????????? doc.execCommand("InsertUnorderedList", False, Nothing)
??????? Case "減少縮進"
??????????? doc.execCommand("Outdent", False, Nothing)
??????? Case "增加縮進"
??????????? doc.execCommand("Indent", False, Nothing)
??????? Case "左對齊"
??????????? doc.execCommand("JustifyLeft", False, Nothing)
??????? Case "居中"
??????????? doc.execCommand("JustifyCenter", False, Nothing)
??????? Case "右對齊"
??????????? doc.execCommand("JustifyRight", False, Nothing)
??????????? ' webBrowserBody.Document.ExecCommand("JustifyFull", false, null);
??????? Case "超鏈接"
??????????? doc.execCommand("CreateLink", True, Nothing)
??????? Case "圖片"
??????????? doc.execCommand("InsertImage", True, Nothing)
??????? Case "撤消"
??????????? doc.execCommand("Undo")
??????? Case "重做"
??????????? doc.execCommand("Redo")
?
查詢狀態(tài)
?????? Me.tb加粗.Pushed = doc.queryCommandState("Bold")
?????? Me.tb傾斜.Pushed = doc.queryCommandState("Italic")
?????? Me.tb下劃線.Pushed = doc.queryCommandState("Underline")
?????? Me.tb序列.Pushed = doc.queryCommandState("InsertOrderedList")
?????? Me.tb園點.Pushed = doc.queryCommandState("InsertUnorderedList")
?????? Me.tb左對齊.Pushed = doc.queryCommandState("JustifyLeft")
?????? Me.tb居中.Pushed = doc.queryCommandState("JustifyCenter")
?????? Me.tb右對齊.Pushed = doc.queryCommandState("JustifyRight")
?
返回設(shè)置控件內(nèi)容:
Public Overrides Property Text() As String
??? Get
??????? Debug.WriteLine(Me.AxWebBrowser1.ReadyState)
??????? Return Me.doc.body.innerHTML
??? End Get
??? Set(ByVal Value As String)
??????? Debug.WriteLine(Me.AxWebBrowser1.ReadyState)
??????? Me.doc.body.innerHTML = Value
??? End Set
End Property
?
?
注意:如果是設(shè)置控件的內(nèi)容,必須查詢Me.AxWebBrowser1.ReadyState的狀態(tài)為READYSTATE_COMPLETE才可以,不然body=Nothing.
如果判斷是否加載完成,AxWebBrowser1_NavigateComplete2事件引發(fā)時說明已加載完成。
轉(zhuǎn)載于:https://www.cnblogs.com/zqonline/archive/2009/05/22/1487231.html
總結(jié)
以上是生活随笔為你收集整理的使用WebBrowser与msHtml开发WinForms下的HtmlEditor控件的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: SQLHELPER C#
- 下一篇: pythonwin 崩溃的解决办法【转贴