使用它的控件及其在文件中的位置保存面板并再次加载它 [英] Save panel with it's controls and their location in file and load it again

查看:81
本文介绍了使用它的控件及其在文件中的位置保存面板并再次加载它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的面板中有多个面板和控件(种类文档创建)。

我想用内部面板存储主面板的状态,并控制位置和值作为模板并再次加载也好。



#NewToCodeProject



谢谢



我尝试了什么:



我尝试将主面板序列化为xml,但它不起作用。

I have panel with multiple panel and controls in it(Kind Of Document Creating).
I want to store Main Panel's state with inner panel and controls location and values as a template and load it again too.

#NewToCodeProject

Thank You

What I have tried:

I've tried serialization of main panel to xml but it did not work.

推荐答案

表单和控件不可序列化。您必须从头开始创建自己的序列化方案。这意味着创建一个数据结构来保存您想要跟踪的所有信息,例如要保存的控件的类型名称,以及重新创建控件及其位置所需的所有数据。



然后您可以将数据结构序列化为文件。



反序列化文件时,您将不得不使用创建所有控件的信息并设置适当的属性,如Top,Left,Width,Height,Text,...或者您正在使用的任何属性。



如果你保存自己保存一条信息,没有什么可以为你做的。



搜索结果 C#自定义序列化 [ ^ ]。
Forms and Controls are not serializable. You have to create your own serialization scheme from scratch. This means creating a data structure to hold all of the information you want to keep track of, such as the type names of the controls you want to save, and all the data required to recreate the controls and their locations.

You can then serialize the data structure to a file.

When you deserialize the file, you'll have to use the information to create all of the controls and set the appropriate properties, like Top, Left, Width, Height, Text, ... or whatever you're using.

If you save save a piece of information yourself, there is nothing that's going to do it for you.

Search results for "C# custom serialization[^]".


这篇关于使用它的控件及其在文件中的位置保存面板并再次加载它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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