Click here to Skip to main content
15,887,485 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
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
VB
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
VB
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
VB
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

*** 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.
Posted
Updated 12-Aug-10 9:26am
v2
Comments
Dalek Dave 12-Aug-10 19:47pm    
Reason for my vote of 5
Well Presented Question

1 solution

You have to use the Font constructor to create a font from a string. That would look something like this:
VB
MainText.Font = New System.Drawing.Font(New System.Drawing.FontFamily("Arial"), 20)
 
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