尝试在鼠标焦点上键入文本时,我得到了不必要的空白行

时间:2012-01-07 11:19:48

标签: c# winforms textbox

我正在使用多行文本框,我可以通过连续键入消息键入消息,或者在按几次回车键的同时键入文本。

所以我的输入可能如下:

This is some text
this is come other text
and some other text

使用SendKeys.Send(txtText.Text + "{enter}");我的输出如下:

This is some text

this is come other text

and some other text

如何删除不必要的新行?

1 个答案:

答案 0 :(得分:2)

尝试,

  string text=txtText.Text;
  txtText.Text=string.Join(Environment.NewLine, 
                    text.Split(new string[] { Environment.NewLine }, 
                    StringSplitOptions.RemoveEmptyEntries));