M
Marco Trapanese
Hello,
I'm sorry if my English is not so good.
I created a usercontrol composed of a picturebox and a label. I also
added few properties to configure its behavior.
In the main form there are a dozen of them, the final user can customize
them through those few properties.
The goal is to save in a file such a configuration (that is the values
of 4-5 properties) in order to recall when needed.
I tried to serialize (binary, soap, xml formatters) the whole
usercontrol and also only the properties I need but without chance.
I got different errors even if I followed several guides found on the web.
So I'd ask you if you can provide me a very short example of "how to
serialize a usercontrol".
I did something like this:
<Serializable()> Public Class IOItem
Inherits UserControl
Public Enum Modes
Button
Toggle
Input
End Enum
Dim _Mode As Modes
Dim _LabelColor As Color
Dim _LabelText As String
Dim _LabelFont As Font
Dim _Config As Boolean = False
Dim _Value As Boolean = False
Public Property Mode() As Modes
Get
Return _Mode
End Get
Set(ByVal value As Modes)
_Mode = value
Update()
End Set
End Property
....
other properties and methods
End Class
In the main form I placed some of this user controls and in the load
event I aggregated them into a generic list (for easy manipulation):
Dim IOItemArray As New List(Of IOItem)
IOItemArray.Add(IoItem1)
IOItemArray.Add(IoItem2)
IOItemArray.Add(IoItem3)
..
..
..
The save sub should do this:
Dim fs As FileStream = New FileStream(diaSaveCfg.FileName, FileMode.Create)
Dim xf As New XmlSerializer(IOItemArray.GetType)
Try
xf.Serialize(fs, IOItemArray)
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
fs.Close()
End Try
In this case I get the following message (copy & paste)
"There was an error reflecting type
'System.Collections.Generic.List`1[IO_Automation.IOItem]'."
Using binary or soap formatters I get other error messages but all of
them tells me I can't serialize my user control.
What's wrong?
Thanks
Marco
I'm sorry if my English is not so good.
I created a usercontrol composed of a picturebox and a label. I also
added few properties to configure its behavior.
In the main form there are a dozen of them, the final user can customize
them through those few properties.
The goal is to save in a file such a configuration (that is the values
of 4-5 properties) in order to recall when needed.
I tried to serialize (binary, soap, xml formatters) the whole
usercontrol and also only the properties I need but without chance.
I got different errors even if I followed several guides found on the web.
So I'd ask you if you can provide me a very short example of "how to
serialize a usercontrol".
I did something like this:
<Serializable()> Public Class IOItem
Inherits UserControl
Public Enum Modes
Button
Toggle
Input
End Enum
Dim _Mode As Modes
Dim _LabelColor As Color
Dim _LabelText As String
Dim _LabelFont As Font
Dim _Config As Boolean = False
Dim _Value As Boolean = False
Public Property Mode() As Modes
Get
Return _Mode
End Get
Set(ByVal value As Modes)
_Mode = value
Update()
End Set
End Property
....
other properties and methods
End Class
In the main form I placed some of this user controls and in the load
event I aggregated them into a generic list (for easy manipulation):
Dim IOItemArray As New List(Of IOItem)
IOItemArray.Add(IoItem1)
IOItemArray.Add(IoItem2)
IOItemArray.Add(IoItem3)
..
..
..
The save sub should do this:
Dim fs As FileStream = New FileStream(diaSaveCfg.FileName, FileMode.Create)
Dim xf As New XmlSerializer(IOItemArray.GetType)
Try
xf.Serialize(fs, IOItemArray)
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
fs.Close()
End Try
In this case I get the following message (copy & paste)
"There was an error reflecting type
'System.Collections.Generic.List`1[IO_Automation.IOItem]'."
Using binary or soap formatters I get other error messages but all of
them tells me I can't serialize my user control.
What's wrong?
Thanks
Marco