简体   繁体   English

在winform C#中重新使用上次使用的数据

[英]Retriving Last Used data in winform C#

I've developed one project in winform with c#. 我用c#在winform开发了一个项目。 There i've used listbox , datagridview and textbox es . 我使用过listboxdatagridviewtextbox What i want to do is that, in the middle of execution accidentally if user closed the winform , we need to save those data and give it back when user restarts the project. 我想做的是,在执行中间,如果用户关闭了winform ,我们需要保存这些数据,并在用户重新启动项目时将其返回。 For this , its better to use database or any other choice is there ? 为此,最好使用数据库还是其他选择? If we are using database how can we store those data dynamically ? 如果我们使用数据库,我们如何动态存储这些数据? is that better to use sqlite ? 使用sqlite更好吗? Can Anyone give me an idea ? 有人可以给我个主意吗?

This is a very general question.You need to serialize the state by yourself somewhow but that depend on many things in your project. 这是一个非常普遍的问题。您需要自己序列化状态,但这取决于项目中的许多事情。

Alternatively you can also take a look at Settings 或者,您也可以查看“设置”

this might also be helpful 可能也有帮助

Are you asking about when the user closes a single form or closes the application entirely? 您是否在询问用户何时关闭单个表单或完全关闭应用程序?

If you just mean closing the single form, you can have the form data stored in a class outside the form class. 如果您只是意味着关闭单个表单,则可以将表单数据存储在表单类之外的类中。 Create a subclass of Main with properties for the form and have it instantiated just prior opening the form. 创建具有窗体属性的Main的子类,并在打开窗体之前对其进行实例化。 It should probably implement IDisposable and call the GC after it's not needed. 它可能应该实现IDisposable并在不需要时调用GC。

Closing the application will require serialization and saving to a file and/or a database. 关闭应用程序将需要序列化并保存到文件和/或数据库中。

I also had to do something like this, I thought it would be best to use: this is a short way of using the settings, just for you c: 我还必须做这样的事情,我认为最好使用:这是一个使用设置的简短方法,只为你c:

private void Form_Load(object sender, EventArgs e)
    {
        if (Properties.Settings.Default.SettingName != "")
        {
            TextBox1.text = Properties.Settings.Default.SettingName;
            //And so on
        }
    }



    private void Form_FormClosing(object sender, FormClosingEventArgs e)
    {
        Properties.Settings.Default.SettingName = //things you want to save;
        //Do it for the rest aswell
    }

"BlockquoteThis is a very general question.You need to serialize the state by yourself somewhow but that depend on many things in your project. “Blockquote这是一个非常普遍的问题。你需要自己序列化状态,但这取决于你项目中的很多东西。

Alternatively you can also take a look at Settings 另外,您也可以查看“设置”

this might also be helpful" ~Kyle 这可能也有帮助”〜Kyle

PS: My reputation isn't high enough to comment, so thats why i had to do it like this. PS:我的声誉不够评论,所以这就是为什么我必须这样做。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM