日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

使用WebBrowser与msHtml开发WinForms下的HtmlEditor控件

發布時間:2025/7/14 编程问答 20 豆豆
生活随笔 收集整理的這篇文章主要介紹了 使用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居然是一個隱藏屬性,找了半天都沒有發現,還以為資料有誤呢。

常用命令:

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")

?

查詢狀態

?????? 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")

?

返回設置控件內容:

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

?

?

注意:如果是設置控件的內容,必須查詢Me.AxWebBrowser1.ReadyState的狀態為READYSTATE_COMPLETE才可以,不然body=Nothing.

如果判斷是否加載完成,AxWebBrowser1_NavigateComplete2事件引發時說明已加載完成。

轉載于:https://www.cnblogs.com/zqonline/archive/2009/05/22/1487231.html

總結

以上是生活随笔為你收集整理的使用WebBrowser与msHtml开发WinForms下的HtmlEditor控件的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。