Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# How do I save runtime font settings

Tags:

c#

I am allowing the users to be able to make their own font choices for a listview. What would you consider the best approach for this. Should I save it to the registry or to a file in the application folder, and what properties should be saved to make sure that the font is redisplayed properly when the application is restarted?

Thanks for your suggestions.

EDIT:

Thanks for all the answers.In answering one of your questions - The machine will not be used for multiple users.

what should I save inorder to recreate the settings.

if I save it to a delimited string can the font class parse this? "Microsoft Sans Serif, 8.25pt, style=Bold"

like image 318
Brad Avatar asked Dec 09 '22 22:12

Brad


1 Answers

Regarding where/how to save application settings see this answer

You can save your font as a string and load it later using following code:

Font font1 = new Font("Arial", 12, FontStyle.Italic);
TypeConverter converter = TypeDescriptor.GetConverter(typeof(Font));
// Saving Font object as a string
string fontString = converter.ConvertToString(font1);
// Load an instance of Font from a string
Font font = (Font)converter.ConvertFromString(fontString);
like image 103
aku Avatar answered Jan 06 '23 03:01

aku