Click here to Skip to main content
15,885,309 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Actual situation:
I have programmed a context menu for a grid. Over this context menu the user can choose a font from a font dialog (font chooser from: http://blogs.msdn.com/b/text/archive/2006/11/01/sample-font-chooser.aspx[^]. With the selected font I create a new style and set it to the grid.

Problem:
No I have to save the font settings into a settings file. The saving mechanismus is fix done with datacontract serializer.
The problem is, that it is not possible to serialize font settings (fontfamily, fontstretch, fontweigth.....) directly because these types are not serialiable?
Has anyone did this once, or am I on the wrong way totally?

Thanks
Posted
Comments
Scott A Parker 3-May-13 16:52pm    
You might want to create an XML file and use it for saving your settings.
stibee 3-May-13 20:08pm    
Yes correct. The mechanisme to do this is fix. But the font most settings are nor serializable.

1 solution

No need to serialize the settings... Just save the settings as they would appear in code and have your application substitute them in the place of the code settings.

C#
public Font AdjustFontSettings()
{
    // Code to read settings here

    string fntFam = "Arial"; // <-- Represented by string stored in settings file
    float fntSize = 15; // <-- Represented by string stored in settings file
    string fntStyle = "Regular"; // <-- Represented by string stored in settings file
    Font myFont = null;

    switch (fntStyle)
    {
        case "Bold":
            myFont = new Font(fntFam, fntSize, FontStyle.Bold);
            break;

        case "Italic":
            myFont = new Font(fntFam, fntSize, FontStyle.Italic);
            break;

        case "Regular":
            myFont = new Font(fntFam, fntSize, FontStyle.Regular);
            break;

        case "Strikeout":
            myFont = new Font(fntFam, fntSize, FontStyle.Strikeout);
            break;

        case "Underline":
            myFont = new Font(fntFam, fntSize, FontStyle.Underline);
            break;
    }

    return myFont;

}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900