Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Storing Font in user settings and isloated storage
Message
De
05/08/2008 11:24:21
Timothy Bryan
Sharpline Consultants
Conroe, Texas, États-Unis
 
 
À
05/08/2008 08:15:08
Information générale
Forum:
ASP.NET
Catégorie:
Formulaires
Versions des environnements
Environment:
C# 3.0
OS:
Vista
Divers
Thread ID:
01336513
Message ID:
01336574
Vues:
14
>I have class
>
>FormData {
> public System.Drawing.Font TextBoxFont;
>}
>
>I need to read/store this class in isolated storage in Winforms application and also in user settings.
>
>Using
>
>XmlSerializer formatter = new XmlSerializer(typeof(FormData),
>"MyNameSpace");
>
>causes exception
>
>System.Drawing.Font cannot be serialized because it does not have a
>parameterless constructor.
>
>How to fix ?

Would something like this work?
public class MyClass
{
public System.Drawing.Font myFont;

public static void Save()
{
     try
     {
          FileStream file = File.Create("mySettings.xml");
          XmlSerializer xml = new XmlSerializer(myClass.GetType());
          xml.Serialize(file, myClass);
          file.Close();
     }
     catch(Exception ex)
     {
          Debug.WriteLine(ex);
     }
}

public static object Load()
{
             if (File.Exists("myClassSettings.xml"))
          {
                try
                {
                    FileStream file = File.Open("mySettings.xml", System.IO.FileMode.Open);
                    XmlSerializer xml = new XmlSerializer(typeof(MyClass));
                    stuff = xmlo.Deserialize(file);
                    file.Close();
                }
               catch
               {
                    Debug.WriteLine(ex);
               }
               return stuff;
          }
}
}
Timothy Bryan
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform