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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > C# >内容正文

C#

Winform可读取html语言,C# Winform 用WebBrowser实现 Html 编辑功能

發(fā)布時間:2023/12/9 C# 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Winform可读取html语言,C# Winform 用WebBrowser实现 Html 编辑功能 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

介紹一款Winform中使用的html editor (Html編輯控件),不過這不是一款新控件,它就是.Net平臺開發(fā)人員所熟知的WebBrowser控件—_—.WebBrowser也可以實現(xiàn)Html編輯和預覽功能。

你只需要使用WebBrowser的設計模式去編輯,用第二個WebBrowser去預覽即可。

為了實現(xiàn)WebBrowser的設計模式,可以使用如下代碼:

這是WYSIWYG編輯器的精簡版本,首先創(chuàng)建一個Form窗體,拖放一個WebBrowser控件。然后在Form_Load事件中加入如下代碼:

VB語言:

Me.WebBrowser1.Navigate("about:blank")

Application.DoEvents()

Me.WebBrowser1.Document.OpenNew(False).Write("

Edit this text")

'turns off document body editing

For Each el As HtmlElement In Me.WebBrowser1.Document.All

el.SetAttribute("unselectable", "on")

el.SetAttribute("contenteditable", "false")

Next

'turns on editable div editing

With Me.WebBrowser1.Document.Body.All("editable")

.SetAttribute("width", Me.Width & "px")

.SetAttribute("height", "100%")

.SetAttribute("contenteditable", "true")

End With

'turns on edit mode

Me.WebBrowser1.ActiveXInstance.Document.DesignMode = "On"

'stops right click->Browse View

Me.WebBrowser1.IsWebBrowserContextMenuEnabled = False

C# 語言:

//CODE in C#

webBrowser1.Navigate("about:blank");

Application.DoEvents();

webBrowser1.Document.OpenNew(false).Write("

Edit this text");

foreach (HtmlElement el in webBrowser1.Document.All)

{

el.SetAttribute("unselectable", "on");

el.SetAttribute("contenteditable", "false");

}

webBrowser1.Document.Body.SetAttribute("width", this.Width.ToString() + "px");

webBrowser1.Document.Body.SetAttribute("height", "100%");

webBrowser1.Document.Body.SetAttribute("contenteditable", "true");

webBrowser1.Document.DomDocument.GetType().GetProperty("designMode").SetValue(webBrowser1.Document.DomDocument, "On", null);

webBrowser1.IsWebBrowserContextMenuEnabled = false;

在webBrowser1.Document.OpenNew(false).Write() 方法中替換你所需要編輯的Html內容即可。

CodeBye 版權所有丨如未注明 , 均為原創(chuàng)丨本網站采用BY-NC-SA協(xié)議進行授權 , 轉載請注明C# Winform 用WebBrowser實現(xiàn) Html 編輯功能!

總結

以上是生活随笔為你收集整理的Winform可读取html语言,C# Winform 用WebBrowser实现 Html 编辑功能的全部內容,希望文章能夠幫你解決所遇到的問題。

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