保存/检索字体设置 [英] Save/retrieve font settings

查看:145
本文介绍了保存/检索字体设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试保存上次使用的字体,字体颜色和背景颜色.然后,当再次启动myapp时,读取数据并使用上次使用的设置.自从开始?
这是我到目前为止的内容:

用户选择新的字体和/或颜色

I am trying to save the last used font, font color, and background color. Then when starting myapp up again, read the data and use the last used settings. Make since?
Here is what I have so far:

User pick new font &/or color

If FontDialog1.ShowDialog() <> Windows.Forms.DialogResult.Cancel Then
            MainText.Font = FontDialog1.Font
            MainText.ForeColor = FontDialog1.Color
        End If
        FontType = FontDialog1.Font.ToString
        FontColor = FontDialog1.Color.ToString


上次使用的字体和颜色已保存到文件


Last used font and color saved to file

FileOpen(1, Application.StartupPath & "\Settings.txt", OpenMode.Output)
WriteLine(1, "Font = " & FontType)
WriteLine(1, "FontColor = " & FontColor)
FileClose(1)



程序在打开时检索上次使用的设置



Program retrieves last used setting when opening

If System.IO.File.Exists(Application.StartupPath & "\Settings.txt") = True Then
    FileOpen(1, Application.StartupPath & "\Settings.txt", OpenMode.Input)
    Do Until EOF(1)
        Input(1, strinput)
        If Trim(strinput).StartsWith("Font") Then
            split = strinput.Split("=")
            FontType= Trim(split(1))
            MainText.Font = FontType '***ERROR HERE
        End If
    Loop
    FileClose(1)
End If


***类型字符串"的值不能转换为"System.Drawing.Font".
除了将值设置为正确的类型外,似乎还需要进行一些修整(除非应该有[花括号]).


我希望外面有人比我聪明.


*** Value of type ''string'' cannot be converted to ''System.Drawing.Font''.
Besides getting the value to the right type, it looks like some more trimming will be necessary as well (unless the [brackets] are supposed to be there).


I hope someone out there is smarter than me.

推荐答案

您必须使用Font构造函数从字符串创建字体.看起来像这样:
You have to use the Font constructor to create a font from a string. That would look something like this:
MainText.Font = New System.Drawing.Font(New System.Drawing.FontFamily("Arial"), 20)


这篇关于保存/检索字体设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆