MyTest test = new MyTest();
test.ShowDialog();
test = null;
MessageBox.Show("hello My name is " + test.Name);
为什么MyTest窗体关闭了,还能访问里面的属性值test.Name?
关闭并没有真正的销毁,所以可以访问
本来就应该这样。
要不怎么获取对话框用户的输入呢?
你看系统对话框也是这样:
OpenFileDialog ofn = new OpenFileDialog();
if (ofn.ShowDialog() == DialogResult.OK)
{
string filename = ofn.FileName; //获得用户选择的文件名
}
如果你非要从语法的角度来说,那就是关闭窗口并不会销毁窗口对应的类。
OpenFileDialog ofn = new OpenFileDialog();
if (ofn.ShowDialog() == DialogResult.OK)
{
string filename = ofn.FileName; //获得用户选择的文件名
因为窗口没用真正的关闭,要destroy的之后就没数据了。
还没调用dispose函数呢