I am new to C# and am working on my first real program, a simple text editor. I would like to allow the user to spell check text in the main richtextbox, richtextbox1. What is the best way for me to do this?
I have to say, this would be a horrible "first program" for someone new to a language. If you have prior programming experience in other languages, particularly in the C family of languages, it wouldn't be too bad but a bad choice for a beginner. Just be sure that you really want to do this as it would be a really involved project to come up with such a program which is still responsive. I definitely don't know the "best" approach to this is but I could see how it might be done. You could probably browse the source of a program which has an open source implementation (e.g., firefox or openoffice). You'll probably get a better result replicating their algorithms. If you are developing a Windows Forms app, this may work: This assumes that the words to be checked are which are currently being typed. Any other words are assumed to have been checked. Have a TextChanged event handler for the (rich)textbox. In the handler, extract the word which currently has the cursor on through the use of the SelectionStart property and search for the word boundaries. You'll need to cross-check the word with a dictionary of correctly spelled words which will be huge. If the word is found in the dictionary, it must be correct. Otherwise, it is probably incorrect (or unrecognized) and you can indicate that through a message or changing the formatting or adorn the word.
1 answers
I have to say, this would be a horrible "first program" for someone new to a language. If you have prior programming experience in other languages, particularly in the C family of languages, it wouldn't be too bad but a bad choice for a beginner. Just be sure that you really want to do this as it would be a really involved project to come up with such a program which is still responsive.
I definitely don't know the "best" approach to this is but I could see how it might be done. You could probably browse the source of a program which has an open source implementation (e.g., firefox or openoffice). You'll probably get a better result replicating their algorithms. If you are developing a Windows Forms app, this may work:
This assumes that the words to be checked are which are currently being typed. Any other words are assumed to have been checked. Have a TextChanged event handler for the (rich)textbox. In the handler, extract the word which currently has the cursor on through the use of the SelectionStart property and search for the word boundaries. You'll need to cross-check the word with a dictionary of correctly spelled words which will be huge. If the word is found in the dictionary, it must be correct. Otherwise, it is probably incorrect (or unrecognized) and you can indicate that through a message or changing the formatting or adorn the word.
answered 2 years ago by:
538
This post was imported from csharpfriends, if you have a similiar question please ask it again.
All previous members have been migrated, hope you enjoy the new platform!