c# - 尝试让对话框窗口记住它的最后位置

标签 c# winforms

我正在用 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/

相关文章:

.net - 使用 WPF 实现 WinForms?

c# - 从按钮打开 excel 文件单击窗口窗体

c# - 从 PictureBox 上传图片到服务器

C# 根据多个值过滤 excel 列

c# - 更改 DataGridView 的行高

c# - 如果没有连接 USB 电缆,则无法使 TCP 客户端代码工作

c# - 使用 C# 以编程方式控制开源 GUI

c# - Linq 查询连接不起作用

c# - 更新 System.Data.SQLite.dll 后 SQLite 无效的 URI

c++ - 二进制 '=' : no operator found which takes a right-hand operand of type 'std::unique_ptr<char [],std::default_delete<_Ty>>'