Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Question regarding For Each Loop issue with Smiley Control

musiccravemusiccrave Posts: 1Member
Hi Guys,


I have tried the RTB control from this page here and its really great... Although I want it to be automatic and not just insert a smiley after clicking a button. Im putting a For each loop on a textchanged event on Trichtextbox1

Basically, I have array of the emoticon Codes (emotCodes= i.e. "Smile | :) " , "Frown | :( , etc ) and an array of the locations(emotLoc = i.e "emots1.gif" , "emots2.gif" , etc )

I have also a sub

[code]Public Sub chooseImage(ByVal imageLoc As String)
Dim theImage As Image = Image.FromFile(imageLoc)
If Not Trestan.Utility.isImageCorrupted(theImage) Then

Dim thePic As New PictureBox()
thePic.Image = theImage
thePic.Size = theImage.Size
Me.TRichTextBox1.AddControl(thePic)
TRichTextBox1.AutoScroll()
End If

End Sub[/code]

Here is what I have so far


[code]Private Sub tRichTextBox1_TextChanged(sender As Object, e As System.EventArgs) Handles TRichTextBox1.TextChanged

For Each st As String In emotCodes


Dim _index As Integer
Dim emotcode As String = ""
_index = TRichTextBox1.Find(st, RichTextBoxFinds.WholeWord)


If _index > -1 Then
If st = emotCodes(0) Then

TRichTextBox1.Select(_index, emotCodes(0).Length)
chooseImage(imageLoc(0))

ElseIf st = emotCodes(1) Then
TRichTextBox1.SelectedText = st
chooseImage(imageLoc(1))
ElseIf st = emotCodes(2) Then
TRichTextBox1.SelectedText = st
chooseImage(imageLoc(2))
End If


End If


Next

End Sub[/code]

What happens is that, it only adds the smiley below the codes and adding them multiple times Frown | :(


Any help would be greatly appreciated. Thanks in advanced Big Grin | :-D


musiccrave
Sign In or Register to comment.