Click here to Skip to main content
15,896,118 members
Please Sign up or sign in to vote.
3.67/5 (2 votes)
See more:
How can I restrict the maximum allowed length in a RichTextBox in WPF so that the user will not be allowed to enter more than a specified number of characters?
Posted
Updated 22-Feb-10 4:25am
v2

have a look on that..

WPF RichText Editor[^]
 
Share this answer
 
Comments
Dalek Dave 22-Jul-11 5:38am    
Nice Link.
hi

Add a method to check the length of the text entered in the key down event of the Rich Text Box..


C#
private void richTexKeyDown(object sender, KeyEventArgs e)
       {
           TextRange tr = new TextRange(richTextBox1.Document.ContentStart ,richTextBox1.Document.ContentEnd);
           if (tr.Text.Length >= 300 || e.Key == Key.Space || e.Key == Key.Enter)
           {
               e.Handled = true;
               return;
           }
       }


please refer http://msdn.microsoft.com/en-us/library/system.windows.documents.textrange.aspx[^]

hope this helps
thanks
 
Share this answer
 
v2
Comments
Dalek Dave 22-Jul-11 5:38am    
Good Call.
 
Share this answer
 
Comments
brental 15-Jun-10 19:20pm    
Reason for my vote of 1
The original poster specifically said the WPF RichTextBox, not the Win Forms one.

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