10
4

1 回答 1

15

这是VB6版本:

Private Sub DHTMLEdit1_onkeypress()
    Dim e As Object
    Set e = DHTMLEdit1.DOM.parentWindow.event
    'Perform smart-quote replacement'
    Select Case e.keyCode
    Case 34: 'Double-Quote'
        e.keyCode = 0
        If IsAtWordEnd Then
            InsertDoubleUndo ChrW$(8221), ChrW$(34)
        Else
            InsertDoubleUndo ChrW$(8220), ChrW$(34)
        End If
    Case 39: 'Single-Quote'
        e.keyCode = 0
        If IsAtWordEnd Then
            InsertDoubleUndo ChrW$(8217), ChrW$(39)
        Else
            InsertDoubleUndo ChrW$(8216), ChrW$(39)
        End If
    End Select
End Sub

Private Function IsLetter(ByVal character As String) As Boolean
    IsLetter = UCase$(character) <> LCase$(character)
End Function

Private Sub InsertDoubleUndo(VisibleText As String, HiddenText As String)
    Dim selection As Object
    Set selection = DHTMLEdit1.DOM.selection.createRange()
    selection.Text = HiddenText
    selection.moveStart "character", -Len(HiddenText)
    selection.Text = VisibleText
End Sub

Private Function IsAtWordEnd() As Boolean

    Dim ch As String
    ch = PreviousChar
    IsAtWordEnd = (ch <> " ") And (ch <> "")

End Function

Private Function PreviousChar() As String

    Dim selection As Object
    Set selection = m_dom.selection.createRange()
    selection.moveStart "character", -1
    PreviousChar = selection.Text

End Function

注意:此解决方案在撤消链中插入了一个附加级别。例如,键入“这是一个测试”会给出一个“这是一个测试”->“这是一个测试”-> “这是一个测试->“->”的链(额外的粗体级别)。要删除这个额外的级别,您必须实施某种PostMessage+subclassing不涉及取消本机按键的解决方案

编辑:如果您的目标是 Windows Vista,请不要忘记包含可再发行的 DHTML 编辑控件。

于 2008-09-15T08:57:53.247 回答