In my quest to smoothly update TextBox characters programmatically, I happened upon the TextBox.Lines property. From its signature
[LocalizableAttribute(true)]
public:
property array<String^>^ Lines {
array<String^>^ get ();
void set (array<String^>^ value);
}
it appears to offer read-write access, however when I update a single line I don’t see the update apply within the debugger nor on-screen. Why does MicroSoft publish misleading headers when it could simply omit the set accessor from the property declaration?
The MSDN entry http://msdn.microsoft.com/en-US/library/system.windows.forms.textboxbase.lines%28v=VS.80%29.aspx offers some confusing advice:
NoteNote
By default, the collection of lines is a read-only copy of the lines in the TextBox. To get a writable collection of lines, use code similar to the following:
textBox1.Lines = new string[] { "abcd" };
But that is not getting any lines at all but instead is setting them. Does that code snippet have further significance in allowing individual lines to be updated? If so, what am I missing?
EDIT
Jon, here’s how I thought I had updated it
for ( int counter = 0; counter < lineStrideInBytes - NEWLINECHARCNT; counter++ )
{
int srcI = LineBeingWrittenI * (lineStrideInBytes) + counter;
replacedLine->Append(TextBoxStr[srcI]);
}
replacedLine->AppendLine(); //NEWLINECHARS
replacedLine[col] = chr; //Updated char
textBox1->Lines[LineBeingWrittenI] = replacedLine->ToString();
Basically when you read the property, it will make a copy. If you change the returned array, that won’t do anything in itself but you can always set the value back. For example (C#):
The important thing here is that you’re writing to the property. Remember that a property is just a getter/setter pair; it’s calling the setter that changes the lines in the text box.