我怎样才能添加一行文本到多线 http://msdn.microsoft.com/en-us/library/system.windows.forms.textboxbase.multiline%28v=VS.80%29.aspx TextBox http://msdn.microsoft.com/en-us/library/system.windows.forms.textbox%28v=VS.80%29.aspx?
例如伪代码;
textBox1.Clear();
textBox1.Lines.Add("1000+");
textBox1.Lines.Add("750-999");
textBox1.Lines.Add("400-749");
...snip...
textBox1.Lines.Add("40-59");
or
textBox1.Lines.Append("brown");
textBox1.Lines.Append("brwn");
textBox1.Lines.Append("brn");
textBox1.Lines.Append("brow");
textBox1.Lines.Append("br");
textBox1.Lines.Append("brw");
textBox1.Lines.Append("brwm");
textBox1.Lines.Append("bron");
textBox1.Lines.Append("bwn");
textBox1.Lines.Append("brnw");
textBox1.Lines.Append("bren");
textBox1.Lines.Append("broe");
textBox1.Lines.Append("bewn");
唯一的方法是文本框.行 http://msdn.microsoft.com/en-US/library/system.windows.forms.textboxbase.lines%28v=VS.80%29.aspx实现(我可以看到)是:
- Clone
- CopyTo
- Equals
- GetType
- 获取哈希码
- 获取枚举器
- 初始化
- 获取下界
- 获取上限
- 获取长度
- 获取长长度
- GetValue
- SetValue
- ToString
@Casperah 指出我的想法是错误的:
- A
TextBox
不have lines
- it has text
- 如果需要,可以将文本在 CRLF 上分割成行
- 但没有这个概念lines
那么问题是如何完成我想要的,而不是 WinForms 让我完成的。
其他给定的变体中也存在细微的错误:
textBox1.AppendText("Hello" + Environment.NewLine);
textBox1.AppendText("Hello" + "\r\n");
textBox1.Text += "Hello\r\n"
textbox1.Text += System.Environment.NewLine + "brown";
当(可能)不需要换行符时,它们会附加或预先添加换行符。
所以,扩展助手:
public static class WinFormsExtensions
{
public static void AppendLine(this TextBox source, string value)
{
if (source.Text.Length==0)
source.Text = value;
else
source.AppendText("\r\n"+value);
}
}
So now:
textBox1.Clear();
textBox1.AppendLine("red");
textBox1.AppendLine("green");
textBox1.AppendLine("blue");
and
textBox1.AppendLine(String.Format("Processing file {0}", filename));
Note:任何代码都会发布到公共领域。无需归属。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)