|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
how to persist color settings in my app?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. Terry,
The in my opinion most simple way is the "Color.ToArgb" and the Color.FromArgb" methods. http://msdn2.microsoft.com/en-us/library/system.drawing.color.toargb.aspx I hope this helps, Cor 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. Show quoteHide quote "Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> wrote in message news:eTYHsAqEGHA.3820@TK2MSFTNGP12.phx.gbl... > Terry, > > The in my opinion most simple way is the "Color.ToArgb" and the > Color.FromArgb" methods. > > http://msdn2.microsoft.com/en-us/library/system.drawing.color.toargb.aspx > > I hope this helps, > > Cor > > 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 Yup, that did it. Thanks!
Show quoteHide quote "Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> wrote in message news:OhC4Gw2EGHA.1816@TK2MSFTNGP11.phx.gbl... > 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" <tolse***@hotmail.com> schrieb: In addition to the other replies: The font handle you obtain using > 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." 'ToHfont' points to the font object the method is called on. This handle won't exist any more if you restart the application. -- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://classicvb.org/petition/> |
|||||||||||||||||||||||