我正在用 C# 创建一个简单的对话窗口,并且想要记住它的放置位置,以便稍后可以在同一位置打开另一个窗口(在同一应用程序运行期间,因此不需要配置文件等)。我可以轻松保存位置(一个点)或边界(一个矩形),但在创建另一个表单时,调用 form.ShowDialog()
会重置两者:
Form form= new Form();
form.Location = ptSavedLocation;
//now form.Location is correct
form.ShowDialog();
//now form.Location is default again, and form is displayed where I don't want it.
如何让表单尊重其位置(或边界,或任何其他适当的属性/ setter )?谢谢!
最佳答案
将表单开始位置设置为手动
例如。
Form form= new Form();
form.StartPosition = FormStartPosition.Manual;
form.Location = ptSavedLocation;
//now form.Location is correct
form.ShowDialog();
//now form.Location is default again, and form is displayed where I don't want it.
关于c# - 尝试让对话框窗口记住它的最后位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/767715/