C#,多行textBox行验证

时间:2017-10-17 16:06:13

标签: c# frameworks

我想知道如何进行多行textBox行验证... 我的问题是我有一个多行文本框,我有一个TCP服务器和客户端,所以客户端不断向服务器发送消息...我有多行文本框来查看这些消息... 我只是想知道如何将最大行数放在100或200上,而旧消息只能从文本框中删除。

简而言之,我希望文本框删除旧行并继续显示新消息。

希望你能帮助我。

我有这段代码,但当它达到100时,它就会停止,我不想停止多个文本框行。

int _lineCount = 1;
        List<string> lines = txtChat.Lines.ToList();
        if (lines.Count >= _lineCount)
        {
            for (int i = _lineCount - 1; i < lines.Count; i++)
            {
                //Split the line when it has more then 100 characters
                if (lines[i].Length <= 100)
                {
                    string line = lines[i];
                    lines[i] = line.Substring(0, 100);
                    lines.Insert(i + 1, line.Substring(100, line.Length - 100));
                    MessageBox.Show(line);
                }
            }
            //Re-assign the lines
            txtChat.Lines = lines.ToArray();
            //Set the cursor to the end of the text
            txtChat.SelectionStart = txtChat.Text.Length;
            //Set new line count.
            _lineCount = txtChat.Lines.Length;
        }

0 个答案:

没有答案
相关问题