Highlighting text to speech in c# windows form -


how highlight text while speaking in c# windows form? tried :

public void highlightwordinrichtextbox(system.windows.forms.richtextbox richtextbox,string word, solidcolorbrush color) {     //clear formatings     //system.windows.controls.richtextbox  rt= (system.windows.controls.richtextbox.ichtextbox;    textrange textrange = new textrange(richtextbox.selectionstart, richtextbox.document.contentend);     textrange.applypropertyvalue(textelement.backgroundproperty, null);     //current word @ pointer     textrange tr = findwordfromposition(textpointer,word);     if (!object.equals(tr, null))     {         //set pointer end of "word"         textpointer = tr.end;         //apply highlight color         tr.applypropertyvalue(textelement.backgroundproperty, color);      } } public textrange findwordfromposition(textpointer position, string word) {     while (position != null)     {         if (position.getpointercontext(logicaldirection.forward) == textpointercontext.text)         {             string textrun = position.gettextinrun(logicaldirection.forward);             // find starting index of substring matches "word".             int indexinrun = textrun.indexof(word);             if (indexinrun >= 0)             {                 textpointer start = position.getpositionatoffset(indexinrun);                 textpointer end = start.getpositionatoffset(word.length);                 return new textrange(start, end);             }         }         position = position.getnextcontextposition(logicaldirection.forward);     }     // position null if "word" not found.     return null; } void reader_speakprogress(object sender, speakprogresseventargs e) {     //show synthesizer's current progress      label2.text= e.text;     solidcolorbrush highlightcolor = new solidcolorbrush(colors.yellow);     highlightwordinrichtextbox(richtextbox1, e.text, highlightcolor); } 

but errors in code got error @ document :

'system.windows.forms.richtextbox' not contain definition 'document' , no extension method 'document' accepting first argument of type 'system.windows.forms.richtextbox' found (are missing using directive or assembly reference ?)

you've used wpf code winforms control. wpf's richtextbox does have document property, winforms's doesn't.

you're looking like:

new textrange(richtextbox.selectionstart, richtextbox.selectionlength); 

Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -