2010-12-02 27 views

Répondre

1

Tout d'abord, utilisez cette extension TextBox et l'appliquer à votre RichTextBox (voir ci-dessous le code, la version complète trouvable here)

public class TextBoxExtension : TextBox 
{ 
public TextBoxExtension(){ } 

public int CurrentLineIndex 
{ 
    get { return this.GetLineFromCharIndex(this.SelectionStart) + 1; } 
} 
} 

font ensuite les éléments suivants:

int maxWordsAllowed = 4; 

private void textChangedEventHandler(object sender, TextChangedEventArgs args) 
{  
    //This get the space character count in your current line 
    if (myRichTextBox.Lines[myRichTextBox.CurrentLineIndex].Split(' ').Length - 1) > maxWordsAllowed) 
     MessageBox.Show("Reached Maximum Words for that line");  
}