一个名为txtEdit的富文本框。
Private Function strLeft(str As String, nLen As Long) As String
If nLen <= 0 Then
strLeft = ""
Else
strLeft = Left(str, nLen)
End If
End Function
Private Sub txtEdit_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
txtEdit.Text = strLeft(txtEdit.Text, txtEdit.SelStart) & vbCrLf & " " & LTrim(Mid(txtEdit.Text, txtEdit.SelStart + 1))
txtEdit.SetFocus
txtEdit.SelStart = Len(txtEdit.Text)
End 但是这段代码的光标和键盘操作不同步,我需要它完全像word里一样,光标总是在即时编辑位置闪烁。
Private Function strLeft(str As String, nLen As Long) As String
If nLen <= 0 Then
strLeft = ""
Else
strLeft = Left(str, nLen)
End If
End Function
Private Sub txtEdit_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
txtEdit.Text = strLeft(txtEdit.Text, txtEdit.SelStart) & vbCrLf & " " & LTrim(Mid(txtEdit.Text, txtEdit.SelStart + 1))
txtEdit.SetFocus
txtEdit.SelStart = Len(txtEdit.Text)
End 但是这段代码的光标和键盘操作不同步,我需要它完全像word里一样,光标总是在即时编辑位置闪烁。
解决方案 »
- 软件狗冲突
- vb打开word,能不能不用open,而直接写入文件流
- Data Report 出现"类没有注册"现象,请问怎么解决!@
- 【急问】DataGrid和RecordSet绑定时,DataGrid中的当前行与RecordSet的游标是不是同步的?
- 函数执行次数的问题,想了一下午,没想出来
- 如何让用户在点击查看一个bmp图像文件后,启动与文件捆绑在一起的程序?
- 如何使picturebox 中的图片消失
- 在VB中如果用几个checkbox控件,请问怎么样才能使几个控件中只要一个被选中了,其他就不能被选中呢?
- 关于ASP的一个问题?
- help me ~~~~help me ~~~~help me ~~~~help me ~~~~help me ~~~~
- 窗体超过屏幕显示范围,如何再增加窗体长度?
- 反编译程序!时间限制问题!!
If nLen <= 0 Then
strLeft = ""
Else
strLeft = Left(str, nLen)
End If
End Function
Private Sub txtEdit1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
Dim lSelPos As Long
lSelPos = txtEdit.SelStart
txtEdit.Text = strLeft(txtEdit.Text, txtEdit.SelStart) & vbCrLf & " " & LTrim(Mid(txtEdit.Text, txtEdit.SelStart + 1))
txtEdit.SetFocus
txtEdit.SelStart = lSelPos
KeyAscii = 0
End If
End Sub
If nLen <= 0 Then
strLeft = ""
Else
strLeft = Left(str, nLen)
End If
End Function
Private Sub txtEdit1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
Dim lSelPos As Long
lSelPos = txtEdit.SelStart
txtEdit.Text = strLeft(txtEdit.Text, txtEdit.SelStart) & vbCrLf & " " & LTrim(Mid(txtEdit.Text, txtEdit.SelStart + 1))
txtEdit.SetFocus
txtEdit.SelStart = lSelPos
KeyAscii = 0
End If
End Sub在句末按回车键时则跳到下一行,并在开头空两格,像这样的效果:
Private Sub txtEdit_KeyPress(KeyAscii As Integer)
If KeyAscii = vbKeyReturn Then
KeyAscii = 0
txtEdit.Text = txtEdit.Text & vbCrLf & " "
txtEdit.SelStart = Len(txtEdit.Text)
End If
End Sub现在如何把上述两个条件整合起来,我发现这两段程序不能并存。
txtEdit.SelText = chr(KeyAscii)
End Sub