Form.Size 在 ApplicationSettings->PropertyBinding 中不可见
我想保存表单位置。我已在 ApplicationSettings->PropertyBinding 中成功设置 Form.Location 属性,但 Form.Size 未在属性绑定列表中列出。为什么?我是否需要添加此属性来使用代码保存属性列表?
I want to save form position. I have successfully set Form.Location property in ApplicationSettings->PropertyBinding but Form.Size is not listed in property binding list. Why? Do I need to add this property to save properties list using code?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Form 类重写 Size 属性以防止其被保存。这是设计使然,它使用 ClientSize 来代替,以便大小不依赖于用户选择的边框宽度。您将在属性绑定列表中找到 ClientSize。
这仍然不是一个好主意,如果窗口最小化或最大化,您不想保存大小。它将无法正常恢复。相反,重写 OnResizeEnd() 方法并仅在 WindowState 为 Normal 时保存大小。
The Form class overrides the Size property to prevent it from getting saved. This is by design, it uses the ClientSize instead so that the size doesn't depend on the border width chosen by the user. You'll find ClientSize in the property binding list.
This is still not a good idea, you don't want to save the size if the window is minimized or maximized. It will not restore properly. Instead, override the OnResizeEnd() method and only save the size if the WindowState is Normal.