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"
如果我将它保存到分隔的字符串,字体类可以解析这个吗? “Microsoft Sans Serif,8.25pt,style = Bold”
3 个解决方案
#1
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);
#2
You should probably use the configuration file (most probably user settings section)... but it's best to avoid saving stuff to the application folder...unless you meant Application Data folder.
您应该使用配置文件(最可能是用户设置部分)...但最好避免将内容保存到应用程序文件夹...除非您的意思是Application Data文件夹。
#3
You could also use isolated storage.
您也可以使用隔离存储。
Really, you need to know if the application is ever shared across user profiles on the same machine. If not, you can get away with storing it in a config file. If it is, then you can use the registry (maintainable), or isolated storage (secure).
实际上,您需要知道应用程序是否在同一台计算机上的用户配置文件之间共享。如果没有,您可以将其存储在配置文件中。如果是,则可以使用注册表(可维护)或隔离存储(安全)。
EDIT: After your last update, you can save typed values in the app config. For example, If I want to save a color, I can save the value as a type System.Color, and the runtime will parse it for me. Check this article for more info and examples.
编辑:上次更新后,您可以在应用程序配置中保存键入的值。例如,如果我想保存颜色,我可以将值保存为System.Color类型,运行时将为我解析它。有关更多信息和示例,请查看此文章。
#1
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);
#2
You should probably use the configuration file (most probably user settings section)... but it's best to avoid saving stuff to the application folder...unless you meant Application Data folder.
您应该使用配置文件(最可能是用户设置部分)...但最好避免将内容保存到应用程序文件夹...除非您的意思是Application Data文件夹。
#3
You could also use isolated storage.
您也可以使用隔离存储。
Really, you need to know if the application is ever shared across user profiles on the same machine. If not, you can get away with storing it in a config file. If it is, then you can use the registry (maintainable), or isolated storage (secure).
实际上,您需要知道应用程序是否在同一台计算机上的用户配置文件之间共享。如果没有,您可以将其存储在配置文件中。如果是,则可以使用注册表(可维护)或隔离存储(安全)。
EDIT: After your last update, you can save typed values in the app config. For example, If I want to save a color, I can save the value as a type System.Color, and the runtime will parse it for me. Check this article for more info and examples.
编辑:上次更新后,您可以在应用程序配置中保存键入的值。例如,如果我想保存颜色,我可以将值保存为System.Color类型,运行时将为我解析它。有关更多信息和示例,请查看此文章。