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

  • 相关阅读:
    BZOJ 2142: 礼物
    八校联考前3场记录
    BZOJ1115:[POI2009]石子游戏Kam (博弈论)
    IE10、IE11解决不能播放Flash的问题!
    ClientAbortException 异常解决办法
    WeX5学习笔记-建立项目且从SVN获取版本
    WeX5学习笔记-创建本地APP相关问题
    android 常见分辨率(mdpi、hdpi 、xhdpi、xxhdpi )屏幕适配
    ERROR 1130 (HY000):Host'localhost'解决方法
    一台机器运行多个JBoss 4.2.3多实例,或多个同一版
  • 原文地址:https://www.cnblogs.com/zqonline/p/1487231.html
Copyright © 2011-2022 走看看