I'm using a RichTextBox class to make some automatic text formatting. And mz question is, how do I get the RichTextBox to put some string immediately after the caret. When I use RichTextBox.CaretPosition.InsertTextInRun("some string") the text is inserted after the current logical block, but I need to be insterted immediately after the caret, in the middle of a Run block. I hope it's clear, thx very much.
            Asked
            
        
        
            Active
            
        
            Viewed 2,232 times
        
    0
            
            
        - 
                    Can you explain by what you mean by 'Run Block'? – t0mm13b Feb 04 '10 at 19:21
 - 
                    Sure, the content in the Richtextbox is stored in a Run class instance (which is a children of FlowDocument, that is used by RichTextBox to store content) – Jan Kratochvil Feb 04 '10 at 19:24
 - 
                    Can you put in the code for the Run class? – t0mm13b Feb 04 '10 at 20:21
 - 
                    see some suggestions at: http://stackoverflow.com/questions/2224243/richtextbox-and-inserting-at-caret-positions – George Birbilis Feb 26 '14 at 18:36
 
2 Answers
0
            
            
        Well, to insert text after the caret i would do this:
        richTextBox1.Select(richTextBox1.SelectionStart, 0);
        richTextBox1.SelectedText = "textToInsert";
If you provide additional information in your question i will attempt to fit my answer better.
        caesay
        
- 16,932
 - 15
 - 95
 - 160
 
- 
                    The thing is, that I'm using the WPF RichTextBox (in System.Windows namespace), that doesn't have Select method. But the solition you suggest fits my problem, I just need it for the WPF RichTextBox. Thx for help. – Jan Kratochvil Feb 05 '10 at 07:59
 
0
            
            
        I think you might have solved this issue by now, but I'll answer anyway.
This is what I used for a similar problem:
public string SelectionText
{
    get { return this.Selection.Text; }
    set { this.Selection.Text = value; }
}
        Tahir
        
- 11
 - 7