c# - Richtext Box-TextChanged Even and checking spaces in current line -
is possible check no. of spaces in current line of richtextbox text changes event... example
lin1: word1 word2 word3 lin2: word1 word2 word3 word4 when type space after word3 shows me message cannot enter word4
first off, use textbox extension , apply richtextbox(see code below, complete version findable here)
public class textboxextension : textbox { public textboxextension (){ } public int currentlineindex { { return this.getlinefromcharindex(this.selectionstart) + 1; } } }
then following:
int maxwordsallowed = 4; private void textchangedeventhandler(object sender, textchangedeventargs args) { //this space character count in current line if (myrichtextbox.lines[myrichtextbox.currentlineindex].split(' ').length - 1) > maxwordsallowed ) messagebox.show("reached maximum words line"); }
Comments
Post a Comment