VB编查找richtextbox里文字且替换为图片
如题比如:点击command1richtextbox1里出现/1然后就自动替换名为1.gif图片出现/2就自动替换为2.gif的图片如果出现两个或者更多都自动换。我有一个...
如题 比如:点击command1richtextbox1里出现 /1 然后就自动替换名为1.gif图片出现/2 就自动替换为2.gif的图片如果出现两个或者更多 都自动换。我有一个查找textbook里的文字替换另段文字的源码。不知道对这个有没有帮助 。我Q28654060分好商量
展开
3个回答
2013-08-11
展开全部
替换有一点帮助,VB里没做过,大体思路因该差不多,主要是定位要插入图片的位置。使用查找,当找到/1,然后确定/1的位置,读取1.gif图片到剪切板,再从剪切板中把图片粘贴大体的代码是:picTemp.Picture = LoadPicture(文件路径及名称)Clipboard.SetData picTemp.PictureRichTextbox.SelStart = 查到的位置
RichTextbox.SetFocusSendKeys "^v", True '模拟键盘输入Ctrl+v
RichTextbox.SetFocusSendKeys "^v", True '模拟键盘输入Ctrl+v
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-08-11
展开全部
Private Const WM_PASTE = &H302
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As LongSub ReplaceImage()
Dim i As Long
Dim pic As String
i = InStr(RichTextBox1.Text, "/")
Do Until i = 0
pic = Mid(RichTextBox1.Text, i)
If InStr(pic, " ") > 0 Then pic = Left(pic, InStr(pic, " ") - 1)
If Dir("C:\" & pic & ".jpg") <> "" Then
Picture1.Picture = LoadPicture("C:\" & pic & ".jpg")
Clipboard.Clear
Clipboard.SetData Picture1.Image
RichTextBox1.SelStart = i - 1
RichTextBox1.SelLength = Len(pic)
SendMessage RichTextBox1.hwnd, WM_PASTE, 0, 0
End If
i = InStr(i + 1, RichTextBox1.Text, "/")
Loop
End Sub
Picture1的autosize设为true,visible设为false
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As LongSub ReplaceImage()
Dim i As Long
Dim pic As String
i = InStr(RichTextBox1.Text, "/")
Do Until i = 0
pic = Mid(RichTextBox1.Text, i)
If InStr(pic, " ") > 0 Then pic = Left(pic, InStr(pic, " ") - 1)
If Dir("C:\" & pic & ".jpg") <> "" Then
Picture1.Picture = LoadPicture("C:\" & pic & ".jpg")
Clipboard.Clear
Clipboard.SetData Picture1.Image
RichTextBox1.SelStart = i - 1
RichTextBox1.SelLength = Len(pic)
SendMessage RichTextBox1.hwnd, WM_PASTE, 0, 0
End If
i = InStr(i + 1, RichTextBox1.Text, "/")
Loop
End Sub
Picture1的autosize设为true,visible设为false
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-08-11
展开全部
'百度HI群&飞度编程学社 1195277'添加一个RichTextBox1控件、一个command控件Private Sub Command1_Click()
Dim a, b As String
a = Replace(RichTextBox1.Text, "/1", "1.gif")
RichTextBox1.Text = a
b = Replace(RichTextBox1.Text, "/2", "2.gif")
RichTextBox1.Text = b
End Sub
Dim a, b As String
a = Replace(RichTextBox1.Text, "/1", "1.gif")
RichTextBox1.Text = a
b = Replace(RichTextBox1.Text, "/2", "2.gif")
RichTextBox1.Text = b
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询