how to persist color settings in my app?

  • Thread starter Thread starter Terry Olsen
  • Start date Start date
T

Terry Olsen

I want to be able to save the user color settings in my app and restore them
when the app is re-opened. I currently have a config file with different
settings such as:

[App Settings]
UID=jsmith
IP=127.0.0.1
Port=23

I want to be able to save the color settings in the same way, but the I
can't convert from System.Drawing.Color to String. How can I accomplish
this?

Thanks.
 
Thanks! That worked great. Now I can't get my font to persist. I tried
writing out the font as Font.ToHfont and then reading it back in as
Font.FromHfont, but I get an error saying "This only works with TrueType
Fonts. This isn't a TrueType Font." The font actually is a TrueType font,
at least it has the .ttf suffix and has the TT logo next to its name in the
listing.

How can I persist my font?

Thanks.
 
Terry,

You are even able to serialize a font.

\\\first showed to me by Tom Shelton
Private Function SerializeFontObject(ByVal fnt As Font) As String
Dim bf As New BinaryFormatter
Dim mem As New MemoryStream
Try
bf.Serialize(mem, fnt)
Return Convert.ToBase64String(mem.ToArray())
Catch
Return String.Empty
Finally
mem.Close()
End Try
End Function


Private Function DeserializeFontObject(ByVal fnt As String) As Font
Dim bf As New BinaryFormatter
Dim mem As New MemoryStream(Convert.FromBase64String(fnt))
Try
Return DirectCast(bf.Deserialize(mem), Font)
Finally
If Not mem Is Nothing Then
mem.Close()
End If
End Try
End Function

I hope this helps,

Cor
 
Terry Olsen said:
Now I can't get my font to persist. I tried writing out the font as
Font.ToHfont and then reading it back in as Font.FromHfont, but I get an
error saying "This only works with TrueType Fonts. This isn't a TrueType
Font."

In addition to the other replies: The font handle you obtain using
'ToHfont' points to the font object the method is called on. This handle
won't exist any more if you restart the application.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top