日期:2014-05-17 浏览次数:21051 次
this.textBox1.Lines[0]=System.DateTime.Now.ToString() ;
[Localizable(true), SRDescription("TextBoxLinesDescr"), Editor("System.Windows.Forms.Design.StringArrayEditor, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(UITypeEditor)), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), MergableProperty(false), SRCategory("CatAppearance")]
public string[] Lines
{
get
{
int num2;
string text = this.Text;
ArrayList list = new ArrayList();
for (int i = 0; i < text.Length; i = num2)
{
num2 = i;
while (num2 < text.Length)
{
char ch = text[num2];
if ((ch == '\r') || (ch == '\n'))
{
break;
}
num2++;
}
string str2 = text.Substring(i, num2 - i);
list.Add(str2);
if ((num2 < text.Length) && (text[num2] == '\r'))
{
num2++;
}
if ((num2 < text.Length) && (text[num2] == '\n'))
{
num2++;
}
}
if ((text.Length > 0) && ((text[text.Length - 1] == '\r') || (text[text.Length - 1] == '\n')))
{
list.Add("");
}
return (string[]) list.ToArray(typeof(string));//返回的是当前文本按回车换行分割出来的一个string 数组,是text的副本,你可以修改这个数组的数据,不影响text,也不报错。很正常,你并没有设置控件
}
set
{
if ((value != null) && (value.Length > 0))
{
StringBuilder builder = new StringBuilder(value[0]);
for (int i = 1; i < value.Length; i++)
{
builder.Append("\r\n");
builder.Append(value[i]);
}
this.Text = builder.ToString();//看到了么,这里对Text进行了设置
}
else
{
this.Text = "";
}
}
}
------解决方案--------------------
string[] lines = this.textBox1.Lines;
lines[0]=System.DateTime.Now.ToString();
this.textBox1.Lines = lines;
------解决方案--------------------