参看
ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.2052/cpguide/html/cpovrserializingobjects.htm在你的MSDN里面,介绍的不错。
ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.2052/cpguide/html/cpovrserializingobjects.htm在你的MSDN里面,介绍的不错。
解决方案 »
- 如何在没有装VS的机子上编译解决方案?
- 有关QQ的数据库
- 如何给条码增加预览功能
- 怎么才能选中datagridview 中的checkbox????
- render 持久化
- .NET Remoting 使用TCP通道,中如何进行身份验证?
- 用.net写过C/S的各位大哥请进!
- listview,toolbar 图片显示bug求救!
- WINDOWS 编程图标问题 看起来简单,高手试试
- 为什么下面使用 接口 而不是 使用对象 直接调用方法 ???
- 带序号的条款内容,如“1.内容1 2.内容2 3.内容3...”,怎么逐条分开它们?
- 请问怎么给DataList中的CheckBox加上CheckedChanged事件
XmlTextWriter writer = null;
writer = new XmlTextWriter(wstream);objSerialize = new XmlSerializer(typeof(ClassName));
objSerialize.Serialize(writer,objClassName);
String strReturnXML = wstream.ToString();
我知道FONT类是可以被序列化的,但是怎么序列呢?我用kelee921的方法不行啊。我写的方法如下:
fontDialog1.ShowColor = true;
fontDialog1.ShowDialog();
Font tempFont = fontDialog1.Font;
XmlSerializer objSerialize; //定义XML序列化对象 StringWriter wstream = new StringWriter();
XmlTextWriter writer = null;
writer = new XmlTextWriter(wstream);
//就在这句话出的错
objSerialize = new XmlSerializer(typeof(Font));
objSerialize.Serialize(writer,tempFont);
String strReturnXML = wstream.ToString();
MessageBox.Show ( strReturnXML );
错误提示:System.Drawing.Font cannot be serialized because it does not have a default public constructor.
请问,怎么解决这个问题呢?
private static extern IntPtr GetStockObject(int fnObject);
public void FromHfont_Example(PaintEventArgs e)
{
// Get a handle for a GDI font.
IntPtr hFont = GetStockObject(0);
// Create a Font object from hFont.
Font hfontFont = Font.FromHfont(hFont);
// Use hfontFont to draw text to the screen.
e.Graphics.DrawString(
"This font is from a GDI HFONT",
hfontFont,
Brushes.Black,
0,
0);
}
供参考……
谢谢您的回答。不过您好象没有看懂我问的问题啊!也许是我没有看懂你的答案!
:)请大家帮帮忙!谢谢
如果想XML Serialize的话该对象是要遵循一些规则的。错误提示已经告诉你font对象不能Xml Serialization了。
BinaryFormatter bf=new BinaryFormatter();
Stream sw=new MemoryStream();
bf.Serialize(sw,f);
byte[] bytes=new Byte[sw.Length];
sw.Seek(0,SeekOrigin.Begin);
sw.Read(bytes,0,bytes.Length);
string str=Convert.ToBase64String(bytes,0,bytes.Length);//将流base64编码后变为
//string
顺便up一下,俺也想知道怎么解决。:)