C# 在两个winform之间保存数据
我还没有找到解决我的问题的方法。我有两个 winform,主窗体和配置设置窗体。可以从主窗体的菜单访问配置设置窗体。
我想要做的是拥有配置设置表单的单个实例,以便当用户在表单中输入信息时,它会传递回主表单并关闭。但是,如果用户决定返回配置设置,则会显示之前输入的信息。
配置设置基本上有两个输入框和一个确定按钮。
我怎样才能实现这个?
I have not been able to find a solution to my problem yet. What I have is two winforms, Main and a Configuration Settings form. The configuration settings form can be accessed from the menu of the Main form.
What I want to do is have a single instance of the Configuration settings form so when the user enters the information in the form it gets passed back to the main form and closes. But if the user decides to go back to the configuration settings form the previous entered information appears.
The configuration settings basically has two input boxes and an OK button.
How can I implement this ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
出于配置目的,您可以使用单例模式来存储配置数据。
在配置表单中,您可以执行以下操作:
存储数据,并在主表单中执行相同的操作来检索数据(因为是同一对象)
此外,您还可以使用 Form Parent 属性将设置显式设置为 MainForm。
For configuration purpose you can use singleton pattern to store configuration data.
In configuration form you can do:
to store data, and same thing in Main form to retrive it (because is the same object)
Also you can use Form Parent property to set settings explicity to MainForm.
你有很多选择。例如:
驱动器\DB(使用一些临时文件)。
关闭时将其返回到调用表单)。
你尝试重新打开它,却让它可见。
当谈到配置窗口时,我喜欢将它们的数据存储到drive\DB或将它们的初始状态传递给构造函数。
You've got many options. For instance:
drive\DB (using some temp file).
return it to the calling form upon close).
you try to reopen it, you make it visible instead.
When it comes to configuration windows, I like to either store their data to the drive\DB or to pass their initial state to the constructor.