首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VB >

多行文本框光标定位,插入字符串解决方法

2012-01-16 
多行文本框光标定位,插入字符串一个多行文本框中有很多内容,现在要在某个位置插入字符串,如果知道光标现在

多行文本框光标定位,插入字符串
一个多行文本框中有很多内容,现在要在某个位置插入字符串,如果知道光标现在所在的位置,并将字符串插入到当前位置??

[解决办法]
Option Explicit

Private Sub Command1_Click()
Dim strTest As String
strTest = "一个多行文本框中有很多内容, " & vbCrLf & "现在要在某个位置插入字符串 "
strTest = InsertStr(strTest, "内容, ", "插入的字符 ")
Debug.Print strTest
End Sub
Private Function InsertStr(strSource As String, strFind As String, strInsert As String) As String
Dim i As Long
i = InStr(1, strSource, strFind)
InsertStr = Left(strSource, i + Len(strFind) - 1) & strInsert & Right(strSource, Len(strSource) - i - Len(strFind) + 1)
End Function
[解决办法]
with text1
.sellength = 0
.seltext = "插入内容 "
end with
[解决办法]
晕,Left函数理解错误
Private Sub Command1_Click()
Dim s1 As String, s2 As String
s1 = Left(Text1.Text, Text1.SelStart)
s2 = Mid(Text1.Text, Text1.SelStart + 1 + Text1.SelLength)
Text1.Text = s1 & "插入的字符串 " & s2
End Sub

热点排行