Click here to Skip to main content
15,867,488 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
OK, how do you delete comments from a RichTextBox after Autocompletion from a ContextMenuStrip? My problem includes the following:

There are words that a user needs to understand before he or she can replace them. This forced me to come up with an idea to put suggestions next to the words that would replace them. Consider the following example:

Opinion(Means: means your idea)


How would you delete such brackets after accepting a suggestion from a contextMenuStrip in VB2010?


The who code is here, please use the dictionary I have provided in Google to test the program. Press F1 to run the program.

https://docs.google.com/document/d/1eTZaIUh7Q9zkNzjZQ-lPV9yxS5eSlNs5ht2-Pl-LS14/edit?usp=sharing[^]


Please create a dictionary file and change the path.
Posted
Updated 25-May-16 22:36pm
v3
Comments
CHill60 17-Dec-15 10:06am    
Don't put the bracketed text in the RichTextBox in the first place
ZurdoDev 17-Dec-15 10:07am    
Means you'd have to look for ( or ) within selected text perhaps.
[no name] 17-Dec-15 10:09am    
Not in the RichTextBox, but from the contextMenuStrip after one accepts a suggestion. It is meant to help one to understand a replacement before he or she replaces it.
CHill60 17-Dec-15 10:11am    
That's not what you said in your question.
You'd have to share how you are building your context menu with these strings
[no name] 17-Dec-15 10:12am    
OK, I will put some code.

1 solution

add the function to your code, then follow the instructions below. the function will check to see if the selected replacement contains a definition and return just the word, otherwise it will just return what was passed as the argument.

VB
Private Function GetWordWithOutBracketedText(SelectedReplacement As String) As String
    if Strings.InStr(SelectedReplacement,"(") = 0 then
      return selectedreplacement
    end if
    Dim arr() As String = Strings.Split(SelectedReplacement,"(")
    Return arr(0)
End Function


then on the line that contains richtextbox1.selectedtext = kamau, change to

Richtextbox1.SelectedText = getwordwithoutbracketedtext(kamau)

let me know if this works. i dont have access to my computer at the moment, but i will double check for you when i get to my computer.
 
Share this answer
 
v2
Comments
[no name] 21-Dec-15 10:40am    
It is close, but you did not understand! The problem was to delete the comments with brackets. E.g Opinion(It means your idea or thoughts). This was done to tell somebody what it means before he or she decided to change the word after replacing text in a richtextbox with a context menu. I only want words like opinion to remain like this. opinion not opinion(It means your idea or thoughts). This will take up space in a sentence and I don't want that.
CoderzF1 21-Dec-15 19:56pm    
oops, just realized a mistake in my function code. in the function, on the line where i give the if statement, change the > 1 to = 0. this should do what you are wanting. i will update the solution to show what i am talking about
[no name] 22-Dec-15 6:07am    
I will test your code now.
[no name] 22-Dec-15 6:35am    
Hey, you are like a brother to me. Thanks. Merry Christmas. I hope you could be the one to help me with the recursion problem am having.
CoderzF1 22-Dec-15 19:56pm    
glad i could help. please mark as accepted solution. have a merry christmas. if there is anything else that you need help with, please feel free to post a separate question. be sure to include example of what you are trying to do(if possible), also any code that will help us to better help you, along with any errors you are getting.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900