如何保存表单内容(控件,控件属性)而不是控件中的数据? [英] How save form content(controls , controls properties) not data in controls ?

查看:90
本文介绍了如何保存表单内容(控件,控件属性)而不是控件中的数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的表单生成带有多个文本框的新表单,并标记如何保存新表单并可以在另一个时间再次检索它?

xml文件可以帮助我解决这个问题吗?



我尝试过:



将WinForms用户控制数据保存为XML [ ^ ]

但无法运行任何人帮助我Vb.net或C#?

i have form that generate new form with multiple textboxs and labels how save new form and can retrieve it again in another time ?
xml file can help me in that problem ??

What I have tried:

Save your WinForms User Control Data to XML[^]
but can't run that anyone help me Vb.net or C# ?

推荐答案

表单及其上的控件不是可以保存的。



您必须构建自己的数据结构,以填充表单和控件属性中的数据,以便您有足够的信息来回读数据并使用它来重新创建形式和控制。这就像表单/控件类型,Top,Left,Width,Height,Text以及您感兴趣的其他任何属性。



你必须遍历作为表单的对象图及其子控件及其子控件,将数据对象添加到表示每个控件的数据结构中。一旦构建了数据结构,就可以将该结构序列化为XML文件。



重建表单正好相反。您回读XML文件,将其反序列化回您的数据结构。然后,您可以根据结构中的数据遍历数据结构,创建控件并设置其属性。



不,我没有示例。
A form, and the controls on it, are not "savable".

You have to build your own data structure to populate with the data from the properties of the form and controls so as you have sufficient information to read back the data and use it to recreate the form and controls. This is stuff like the form/control type, Top, Left, Width, Height, Text, and whatever other properties you're interested in.

You would have to walk the object graph that is your form and it's child controls, and their child controls, adding data objects to your data structure representing each control. Once you've built your data structure, you can then serialize that structure to an XML file.

Rebuilding the form is the opposite. You read back the XML file, deserializing it back into your data structure. You then walk your data structure, creating the controls and setting their properties based on the data you have in the structure.

No, I don't have an example.


如果使用Designer创建表单,则重新创建表单所需的所有数据(由Designer自动存储)在表单的Designer-Script中(用于例如:'Form2.Designer.vb')。此脚本包含一个Standard-VB.Net-Method(称为'InitializeComponent')。此方法包含构建表单所需的所有设置。

您现在要做的是,如果你想动态地创建一个/这个表格是:

- 实例所需的控件(就像在Designer-Script中完成的那样)

- 为你创建所需的设置控件 - 这意味着位置,也许你想要一个不同的字体,也许是颜色设置等等



当然你可以将这些信息存储在XML中-File(或您喜欢的任何其他格式)。如果用户可以更改某些属性,那么这样做可能很有用。如果设置是固定的(不可更改),您也可以使用您已经创建表单的方法来完成。



我也没有示例为此... :(
If you create a Form with the Designer all the data, which is needed to re-create the Form is stored (automaticly by the Designer) inside the Designer-Script from the Form (for example : 'Form2.Designer.vb'). This Script is contains a Standard-VB.Net-Method (called 'InitializeComponent').This Method hold all the Settings which are required to build the Form.
What you have to do now is, if you want to create a/this Form dynamicly is :
- instance the required Controls (like it is done in the Designer-Script)
- make the needed Settings for the Controls - this means the Location, perhaps you like to have a different Font, perhaps the Color-Settings and so on

Of course you could store this Information inside a XML-File (or any other Format you like). To do it like this could be useful if some of the Properties could be changed by the User. If the Settings are fixed (not changeable) you could also do it with the Method which you allready have to create the Form.

I also don't have an example for this ... :(


这篇关于如何保存表单内容(控件,控件属性)而不是控件中的数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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