Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# .NET
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 21-Feb-10 19:58pm
Edited 22-Feb-10 4:25am
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

have a look on that..
 
WPF RichText Editor[^]
  Permalink  
Comments
Dalek Dave at 22-Jul-11 5:38am
   
Nice Link.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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

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
  Permalink  
v2
Comments
Dalek Dave at 22-Jul-11 5:38am
   
Good Call.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

  Permalink  
Comments
brental at 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)

  Print Answers RSS
0 CPallini 209
1 Sergey Alexandrovich Kryukov 201
2 Nirav Prabtani 198
3 Mika Wendelius 170
4 OriginalGriff 167
0 Nirav Prabtani 398
1 OriginalGriff 292
2 Sergey Alexandrovich Kryukov 251
3 Mika Wendelius 185
4 Abhinav S 180


Advertise | Privacy | Mobile
Web01 | 2.8.140721.1 | Last Updated 22 Jul 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100