类似于WYSIWYG(所见即所得)编辑器 我希望用户能够直观地编辑html文档并移动对象。如何为Web浏览器控件启用这些html编辑功能?
我的环境是Visual Studio 2010,Windows 7 64位。
我想启用网络浏览器控件的html编辑功能 (http://msdn.microsoft.com/en-us/library/aa752040%28v=VS.85%29.aspx)。
注意:Web浏览器控件的代码正在专用编辑器中使用,并且太大而且数量众多,无法在此发布,但如果有人想要完整的源代码,我可以稍后发布链接。这是一个大型项目,请参考此处,因为我试图在发布或在此之前进行交谈和搜索谷歌:http://social.msdn.microsoft.com/Forums/vstudio/en-US/1e5acdb2-9366-4258-890a-86eaaa1086ee/html-expert-needed。
答案 0 :(得分:2)
WebBrowser控件有一个内置的WYSIWYG迷你 - HTML编辑器。你可以使用它。 以下是如何打开编辑模式的示例:
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
' I do this for this example, so that we have some elements loaded.
' For you, you will need to add the tags from your code for various HTML elements.
WebBrowser1.Navigate("http://google.com")
End Sub
Private Sub WebBrowser1_DocumentCompleted(sender As System.Object, e As WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
' To turn On the edit mode.
Dim axObj As New Object
axObj = WebBrowser1.ActiveXInstance
axObj.document.designmode = "On"
End Sub
答案 1 :(得分:0)
对于在这里阅读本文的新人来说,相关的代码部分最终解决了我在上面的msdn论坛帖子中引用的所有内容:
Private Sub wb_DocumentCompleted(ByVal sender As Object,ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs)句柄 wb.DocumentCompleted 'Tabp.wb_DocumentCompleted - Internet相关文档完成例程
If doc IsNot Nothing Then If m_EditMode = True Then doc.designMode = "On" Else doc.designMode = "Off" End If End If If wb.Document IsNot Nothing Then HTMLDOC = wb.Document If wb.CanGoBack Then mbBack.ImageIndex = ImglstImages.cVLeftArrowQuiescent mbBack.Enabled = True Else mbBack.ImageIndex = ImglstImages.cVLeftArrowGreyed mbBack.Enabled = False End If If wb.CanGoForward Then mbforward.Enabled = True mbforward.ImageIndex = ImglstImages.cVRightArrowQuiescent Else mbforward.Enabled = False mbforward.ImageIndex = ImglstImages.cVRightArrowGreyed End If wb.AllowNavigation = False cmbxAddressbar.Text = wb.Url.ToString AddIfUnique(cmbxAddressbar.Text) If Form1.GetClassIdentifier = m_ClassIdentifier Then Form1.ProgBar.Visible = False wb.AllowNavigation = True PU.Clear() ''''' wb.Focus() End Sub
这就是我所有解决的问题。总结一下他们使用的代码存在两个主要问题: