How do I serialize Font object into a string that I can store in either
INI file or the registry (I know it¢s a bad thing, but need to do it
nevertheless). Then, also, how do I deserialize it from that string
back into a font object?
Thanks.
Frank...
Here is a little bit of code using a binary formatter to convert a font
object into a base-64 string:
Option Strict On
Option Explict On
Imports System.IO
Imports System.Runtime.Serialization
Imports System.Runtime.Serialization.Formatters.Binary
.....
' Basic error handling - you'll want to improve

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
' again, very basic handling..
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
HTH