参看
ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.2052/cpguide/html/cpovrserializingobjects.htm在你的MSDN里面,介绍的不错。

解决方案 »

  1.   

    XmlSerializer objSerialize;        //定义XML序列化对象StringWriter wstream = new StringWriter();
    XmlTextWriter writer = null;
    writer = new XmlTextWriter(wstream);objSerialize = new XmlSerializer(typeof(ClassName));
    objSerialize.Serialize(writer,objClassName);
    String strReturnXML = wstream.ToString();
      

  2.   

    System.Drawing.Font本身就支持序列化
      

  3.   

    Samen168:
        我知道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.
    请问,怎么解决这个问题呢?
      

  4.   

    MSDN上有例子的,很全,我也做过,在上面找的,代码也很多
      

  5.   

    [System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")]
    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);
    }
    供参考……
      

  6.   

    To: mywebcom
        谢谢您的回答。不过您好象没有看懂我问的问题啊!也许是我没有看懂你的答案!
        :)请大家帮帮忙!谢谢
      

  7.   

    楼主要的是XML序列化,MyWebCom给的是Binary Serialization。
    如果想XML Serialize的话该对象是要遵循一些规则的。错误提示已经告诉你font对象不能Xml Serialization了。
      

  8.   

    Font f=this.Font;  //使用当前默认窗体的font做测试
    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
      

  9.   

    micropentium6(小笨|想学ASP) ,用你的代码出来的结果似乎不是xml格式呀。
    顺便up一下,俺也想知道怎么解决。:)
      

  10.   

    是不是说FONT这个类不能被XML序列化?还请问,怎么将序列化后的内容还原成一个FONT的实例呢?也就是怎么反序列化呢?