zoukankan      html  css  js  c++  java
  • 使用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事件引发时说明已加载完成。

  • 相关阅读:
    OpenCV-Python 霍夫直线检测-HoughLinesP函数参数
    2017 年度读书总结
    检查服务是否正在运行,如果未运行则启动
    添加MIME类型
    IIS功能查看、配置
    IIS下的身份验证方式管理
    PowerShell管理IIS(新建站点、应用程序池、应用程序、虚拟目录等)
    虚拟目录和应用程序的区别
    远程重启服务器
    逐行读取txt
  • 原文地址:https://www.cnblogs.com/zqonline/p/1487231.html
Copyright © 2011-2022 走看看