如何保存用户控制? [英] How do I save user control?

查看:96
本文介绍了如何保存用户控制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为多个页面进行了用户控制,每个页面都进行数学运算并在用户控件内部生成标签,现在我希望这些结果保持不变,并且在退出程序时不会更改。我应该在关闭事件中放置什么,以及我还应该做些什么才能节省用户控制权?



我尝试了什么:



I made user control for multiple pages, each is doing mathematical operations and making result in label inside user control, now i want those results to stay same and not change when i quit program. What should i put in "closed" event in from, and what else should i do in order to save user control?

What I have tried:

private void Form1_FormClosed(object sender, FormClosedEventArgs e)
        {
            
            Properties.Settings.Default.Save();
        }

推荐答案

没有人能告诉你该放什么。



我们对您的控制,您如何管理应用中的数据以及保存数据的位置一无所知。



我得到了不同的砍伐你正在使用你的控件管理你的数据存储,这是错误的做事方式。



UserControls,以及所有控件,都是用于编辑和显示数据。您的应用程序应该将其数据保存在可序列化的结构中,这样可以轻松地将数据保存到任何您想要的位置。



控件本身根本不暴露任何方法告诉他们为你保存你的数据。
Nobody can tell you what to put there.

We know absolutely nothing about your control, how you're managing data in your app, and where you're saving the data.

I get the distinct felling you're using your controls to mange your data "store" and that's the wrong way to do things.

UserControls, and all controls for that matter, are used to edit and display data. Your application should be maintaining its data in structures that are serializable, making it easy to save data to just about anywhere you want.

Controls themselves expose no method at all to tell them to "save your data" for you.


这篇关于如何保存用户控制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆