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事件引发时说明已加载完成。

  • 相关阅读:
    Hashtable,挺爽的一个东西,大家都用烂了吧,我再画蛇添足一下。
    今天你写控件了吗?ASP.net控件开发系列(八)
    Attribute在运行期赋值?
    整几个题给大家玩玩,看看“下盘功夫”怎样
    当stringFormat碰上{和}
    一句SQL语句解决倒序数据分页提取
    C#扩展一般用于linq
    字符串转日期类型
    Dispatcher与UI线程交互
    圆形进度条
  • 原文地址:https://www.cnblogs.com/zqonline/p/1487231.html
Copyright © 2011-2022 走看看