保存 Windows 窗体大小
我正在用 VB.NET 开发一个作品。 在我的主表单中,我正在创建一个新表单以用作对话框。 我想知道是否有一种方法可以在新对话框关闭时保存每个用户的大小设置(可能通过 XML 或其他方式保存在他们计算机上的文件中?)
I'm developing a piece in VB.NET. Inside my primary form, I'm creating a new form to use as a dialog. I was wondering if there was a way to, upon the close of the new dialog, save it's size settings for each user (probably in a file on their machine, through XML or something?)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
您可以将其保存到设置文件中,并在“onclose”事件时更新它。
要进行设置,请转到项目属性 -> 设置 -> 然后进行类似 system.drawing.size 类型的“dialogsize”设置。
然后在对话框中执行此操作:
执行类似的操作来检查并使用设置:
you can save it to the settings file, and update it on the 'onclosing' event.
to make a setting goto Project Properties ->settings -> then make a setting like 'dialogsize' of type system.drawing.size.
then do this in your dialog form:
do something like this to check and use the setting:
虽然这是针对C#,它对 VB.Net 也有帮助。
Although this is for C#, it will help with VB.Net as well.
您还可以向应用程序添加新设置(尺寸)并将其设置为 system.drawing.size
然后,确保在关闭时将当前尺寸保存到设置中。
并在加载时应用您在设置中保存的尺寸
You can also add a new setting to your application (size) and set it to
system.drawing.size
Then, you make sure you save the current size to settings on close.
and on load you apply the size you have saved in settings
这是我在网上找到的解决方案 这似乎对我来说效果很好。
前面提到的一些解决方案没有按预期为我工作。 根据我的表单在关闭时所处的位置,当我再次加载表单时,该表单不会重新定位回该确切位置。
该解决方案似乎还通过考虑其他一些因素来解决问题:
您需要在“项目属性”->“项目属性”下设置这两个设置。 设置: WindowLocation 和 WindowSize 如下所示:
然后创建以下函数:
接下来,您需要向表单的加载和关闭事件添加代码,如下所示:
我希望有所帮助。
Here's a solution that I found online that seems to work rather well for me.
Some of the previously mentioned solutions weren't working for me as expected. Depending on where my form was positioned at the time of closing the form wouldn't get repositioned back to that exact location when I would load it again.
This solution seems to do the trick by taking into account some other factors as well:
You need to set up these two setting under Project Properties -> settings: WindowLocation and WindowSize like so:
Then create the following function:
Next, you'll need to add code to your form's load and closing events like so:
I hope that helps.
您还可以使用 VB.NET IDE 本身提供的 UI 来完成此操作。 在表单的属性窗格中,查看名为“(应用程序设置)”的项目,然后查看“属性绑定”。 您可以将表单的几乎每个属性(包括大小和位置)绑定到该应用程序的设置值。
You can also do this using the UI provided by the VB.NET IDE itself. In the properties pane for a form, look under the item called "(Application Settings)" and then under "Property Binding." You can bind just about every property of the form (including size and location) to a settings value for that application.
事实证明,我找到了一种使用 System.IO.IsolatedStorage 来做到这一点的方法
As it turns out, I found a way to do this using the
System.IO.IsolatedStorage