Reputation: 382
I am using a RichTextBox
control on my form. I want a small code which can detect if any image has been inserted in the rtb or not. (IDE VS 2008)
For e.g. user can just type some text or insert image also (Ctrl + V). Now if we select an image then we can get the type but I want a code which scans contents of rtb and gives me a true if an image is inserted or false if there is none.
Upvotes: 4
Views: 3211
Reputation: 949
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
OpenFileDialog1.ShowDialog()
Dim img As Image = Image.FromFile(OpenFileDialog1.FileName)
Clipboard.SetImage(img)
RichTextBox1.Paste()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button2.Click
MsgBox("contains image: " & RichTextBox1.Rtf.Contains("\pict\wmetafile8\"))
End Sub
it searches the richtextbox inner code, "\pict\wmetafile8\" is the pic tag.
Upvotes: 4