Classes array to Byte array / VB .NET
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
Public Class Form1 Dim T As New List(Of Test) Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim OFD As New OpenFileDialog If OFD.ShowDialog <> Windows.Forms.DialogResult.OK Then Exit Sub Dim Tmp As New Test With {.BM = New Bitmap(OFD.FileName)} T.Add(Tmp) End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Dim formatter As New Runtime.Serialization.Formatters.Binary.BinaryFormatter() Dim stream As New IO.MemoryStream formatter.Serialize(stream, T) stream.Close() IO.File.WriteAllBytes("C:\1111.txt", stream.ToArray) End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click Dim formatter As New Runtime.Serialization.Formatters.Binary.BinaryFormatter() Dim B() As Byte = IO.File.ReadAllBytes("C:\1111.txt") Dim stream As New IO.MemoryStream(B) T = formatter.Deserialize(stream) stream.Close() End Sub Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click Try Me.BackgroundImage = T(TextBox1.Text).BM Catch ex As Exception End Try End Sub End Class <system.serializable()> Class Test Public BM As Bitmap End Class |