序列化动态创建Form对象 [英] Serialize a dynamically create Form objects

查看:49
本文介绍了序列化动态创建Form对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我对序列化有疑问。

我已经制作了一个表单对象并动态添加了一些控件。

所以,我想保存该表单及其中的控件。

这就是为什么我决定序列化表单对象。

但是当我调用序列化表单对象时,发生了异常。



Hello guys,

I have question on serialization.
I have made a form object and added some controls in it dynamically.
So, I want to save that form along with the controls in it.
That's why I decided to serialize the form object.
But when I call serialize the form object, an exception occurred.

BinaryFormatter objBinaryFormatter = new BinaryFormatter();
FileStream objFileStream = new FileStream(strCompleteFilePath, FileMode.OpenOrCreate);
objBinaryFormatter.Serialize(objFileStream, formObject);





输入'System.Windows.Forms.Form'in程序集'System.Windows.Forms,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089'未标记为可序列化。



任何人都可以帮助我。

我们不能序列化表格对象。

如果可以的话,请提出一些答案。



感谢advnace



Type 'System.Windows.Forms.Form' in Assembly 'System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' is not marked as serializable.

Can anybody help me in this.
Cant we serialize a form object.
If we can, then please suggest some answers.

Thanks in advnace

推荐答案

Forms 等UI对象并不意味着序列化这样,你最好在表单中创建一个状态对象,这将保留有用的信息并反而序列化该对象。
UI objects like Forms etc. are not meant to be serialized in this way, you are better off creating a "state" object within your form which will keep useful information and serialize that object instead.


这篇关于序列化动态创建Form对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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