0

如何通过按下 vc++ 2008 中的按钮来完全删除(销毁)文本框(不删除其中的文本)?Windows 窗体应用程序,我创建了 textBox1,并且我希望该文本框在用户点击某个按钮时消失(不是通过使用可见功能,我希望它被破坏)

4

1 回答 1

0

我假设您正在谈论 C++/CLR 应用程序。如果是这种情况,您需要使您的控件不可见,并将其从容器表单的控件集合中删除(并将 NULL 分配给指向它的任何其他变量......)。

您的代码应如下所示:

private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
             this->textBox1->Visible = false;
             this->Controls->Remove(this->textBox1);
             this->textBox1 =  nullptr; // if you do not have any other reference to this object, it should be disposed eventually by garbage collection
         }
于 2012-04-25T20:32:05.223 回答