0

いいえを確認することは可能ですか。リッチテキストボックスの現在の行のスペースとそのテキスト変更イベント...たとえば

lin1: word1 word2 word3
lin2: word1 word2 word3 word4

when i type space after word3 it shows me message that you cannot enter word4
4

1 に答える 1

1

まず、このTextBox拡張機能を使用して、RichTextBoxに適用します(以下のコードを参照してください。完全なバージョンはここにあります) 。

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

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

次に、次の手順を実行します。

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");    
}
于 2010-12-03T10:17:12.877 に答える