I can remove last char from textBox by
textBox1->Text = textBox1->Text->Remove(textBox1->Text->Length - 1);
And I want to do it creating a reference or a pointer to the Text. But I can't do it like this
String^ t = textBox1->Text;
t = t->Remove(t->Length - 1); // Text doesn't change
P.S. Any of this doesn't compile:
String* t = textBox1->Text; // error: an ordinary pointer to a
// C++/CLI ref class or interface class
// is not allowed
String& t = textBox1->Text; // error: an ordinary reference to a
// C++/CLI ref class or interface class
// is not allowed
String% t = textBox1->Text // error: a tracking reference to a
// System::String is not allowed
答案 0 :(得分:2)
t = t->Remove(t->Length - 1);
只需更改本地引用(pointer-thingy,handle,...)t
,以引用Remove
返回的字符串。
文本框字符串不会因此而改变。
当你这样做时
textBox1->Text = t;
...您正在为属性 Text
调用 setter函数,此setter函数不仅会更改文本框字符串数据,还会更新或更新至少使文本框显示无效。