我可以在 FormClosed 中保存表单大小和位置吗?
Can I save form size and location in FormClosed?
跟帖.NET / Windows Forms: remember windows size and location中给出了多种保存表格大小和位置的方案。但是,他们都建议将信息保存在 FormClosing
事件处理程序中。我很好奇:在FormClosed
中保存信息有什么问题吗?这对我来说似乎更自然,因为那是我们确定表单正在关闭的事件。当我测试时,这两个事件似乎都能正常工作。
It seems more natural to me, because that is the event where we are
certain the form is being closed.
FormClosing
发生在 FormClosed
事件之前。除非你在FormClosing
事件中取消,否则你仍然可以确定它会被关闭。
You can use this event to perform tasks such as freeing resources used
by the form and to save information entered in the form or to update
its parent form.
但是请注意,无论何时关闭程序的启动窗体,整个应用程序都应自动退出。
如您所见,它在大多数时间都有效。但是您可能会不时遇到一些奇怪的行为(不保存设置)。
在保存大小和位置时,需要考虑更多棘手的事情,尤其是当您有多个具有不同 resolutions/size 等的显示器时。因此,我会排除一个可能的风险。因此,除非有充分的理由使用 FormClosed
,否则我会为此目的使用 FormClosing
。
跟帖.NET / Windows Forms: remember windows size and location中给出了多种保存表格大小和位置的方案。但是,他们都建议将信息保存在 FormClosing
事件处理程序中。我很好奇:在FormClosed
中保存信息有什么问题吗?这对我来说似乎更自然,因为那是我们确定表单正在关闭的事件。当我测试时,这两个事件似乎都能正常工作。
It seems more natural to me, because that is the event where we are certain the form is being closed.
FormClosing
发生在 FormClosed
事件之前。除非你在FormClosing
事件中取消,否则你仍然可以确定它会被关闭。
You can use this event to perform tasks such as freeing resources used by the form and to save information entered in the form or to update its parent form.
但是请注意,无论何时关闭程序的启动窗体,整个应用程序都应自动退出。
如您所见,它在大多数时间都有效。但是您可能会不时遇到一些奇怪的行为(不保存设置)。
在保存大小和位置时,需要考虑更多棘手的事情,尤其是当您有多个具有不同 resolutions/size 等的显示器时。因此,我会排除一个可能的风险。因此,除非有充分的理由使用 FormClosed
,否则我会为此目的使用 FormClosing
。