我正在用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.
如何让表单尊重其位置(或界限,或任何其他适当的属性/设置者)?谢谢!
答案 0 :(得分:4)
将表格开始位置设置为手动
例如
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.
答案 1 :(得分:0)
将表单StartPosition属性设置为Manual