Serialize Controls

  • Thread starter Thread starter Gabriel Ferrarini
  • Start date Start date
G

Gabriel Ferrarini

It may possible to serialize controls like buttons and textbox? How to do?

I have tried XmlSerialization, BinaryFormatter, SoapFormatter, but whitout
success. I receive a message informing that the class is not marked as
serializable.

Thanks.
 
Gabriel Ferrarini said:
It may possible to serialize controls like buttons and textbox? How to do?

I have tried XmlSerialization, BinaryFormatter, SoapFormatter, but whitout
success. I receive a message informing that the class is not marked as
serializable.

Thanks.

Use inheritance and serialise information about non-persistible controls.

Imports System.Runtime.Serialization
Imports System.Security.Permissions

<Serializable()> _
Public Class MyButton

Inherits Button
Implements ISerializable

Private Const MEMBER_NAME = "Name"
Private Const MEMBER_WIDTH = "Width"
Private Const MEMBER_HEIGHT = "Height"
Private Const MEMBER_TEXT = "Text"

Public Sub New()

End Sub

Protected Sub New(ByVal info As SerializationInfo, ByVal context As _
StreamingContext)

Me.MyHeight = info.GetInt32(MEMBER_HEIGHT)
Me.MyName = info.GetString(MEMBER_NAME)
Me.MyText = info.GetString(MEMBER_TEXT)
Me.MyWidth = info.GetInt32(MEMBER_WIDTH)

End Sub

<SecurityPermissionAttribute(SecurityAction.Demand, _
SerializationFormatter:=True)> _
Public Sub GetObjectData(ByVal info As _
System.Runtime.Serialization.SerializationInfo, ByVal context As _
System.Runtime.Serialization.StreamingContext) Implements _
System.Runtime.Serialization.ISerializable.GetObjectData

info.AddValue(MEMBER_HEIGHT, Me.MyHeight)
info.AddValue(MEMBER_NAME, Me.MyName)
info.AddValue(MEMBER_TEXT, Me.MyText)
info.AddValue(MEMBER_WIDTH, Me.MyWidth)

End Sub

Public Property MyName() As String
Get
Return Me.Name
End Get
Set(ByVal value As String)
Me.Name = value
End Set
End Property

Public Property MyWidth() As Integer
Get
Return Me.Width
End Get
Set(ByVal value As Integer)
Me.Width = value
End Set
End Property

Public Property MyHeight() As Integer
Get
Return Me.Height
End Get
Set(ByVal value As Integer)
Me.Height = value
End Set
End Property

Public Property MyText() As String
Get
Return Me.Text
End Get
Set(ByVal value As String)
Me.Text = value
End Set
End Property

End Class
 
Back
Top