我有一个旧的,遗留的VB6应用程序,它使用D
HTML编辑控件作为
HTML编辑器. Microsoft DHTML编辑控件,一个DHTMLEd,可能只不过是一个使用IE自己的内部编辑功能的IE控件.
我想修改应用程序来实现Word的智能引号.具体来说,“被替换为”或“,”被替换为“或”,因为它被输入;如果用户在更换后立即按Ctrl Z,则可以回到直接引用.
有人有代码吗?
如果您没有DHTML / VB6的代码,但确实有JavaScript代码可以在具有contentEditable区域的浏览器中使用,我也可以使用它
解决方法
这是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子类化解决方案,它不涉及取消本机按键
编辑:如果您定位到Windows Vista,请不要忘记包含DHTML Editing Control redistributable.