Writing/reading control properties to a file

  • Thread starter Thread starter John
  • Start date Start date
J

John

Hi

I am trying to save settings of controls on my form to a file so I can read
them back later and recreate the controls on the form. I have figured out
how to go through all controls and get their properties (see code below).
What I am not sure is; how and what type of file format I need to save the
info to and how to read it back. Would appreciate any help on that. A code
snippet would be very much appreciated.

Many thanks

Regards


For Each Ctrl In rootControl.Controls
Props = TypeDescriptor.GetProperties(Ctrl)
' Write control name to a file here - how?
For Each Prop In Props
If Prop.IsBrowsable Then
PropName = Prop.Name
PropValue = Prop.GetValue(Ctrl)
' Write control properties to a file - how?
End If
Next
Next
 
i personally would just serialize and deserialize the hole control to disk ,
much easier

regards

Michel
 
Presumably deserialize requires knowing what object type to expect when
reading file? My problem is my appe will not know beforehand what objects to
expect. Would deserialize still work?

Thanks

Regards
 
Just to clear this up..I need to read the file (xml if it may) then see what
control is specified (without knowing which one to expect beforehand) and
its properties and then cerate the relevant control on the form. Basically I
am trying to create a sort of a template system for forms with different
settings for controls and their respective properties for different clients.
Just so I don't have to have separate hard coded versions of forms for each
clients and one form would do with separate template (xml?) file for each
client.

Thanks

Regards
 
well for serializing and deserializing you must at least have an interface
if you can provide a generic interface in your situation ...... then it is
possible

regards

Michel
 
well i use this


''' <summary>
''' maakt van een byte array een object
''' </summary>
''' <param name="Argdata">de ruwe binaire data </param>
''' <returns></returns>
Private Function DeSerialize(ByVal Argdata() As Byte) As Object
Dim m As New MemoryStream(Argdata)
Dim b As New BinaryFormatter()
m.Seek(0, 0) 'start
Return b.Deserialize(m)
End Function
''' <summary>
''' Maakt van een Object (foo) een byte array .
''' </summary>
''' <param name="Argdata">argdata als foo object</param>
''' <returns></returns>
Private Function Serialize(ByVal Argdata As Object) As Byte()
Dim b As New BinaryFormatter
Dim m As New MemoryStream
b.Serialize(m, Argdata)
m.Seek(0, 0) 'start
Return m.ToArray
End Function


to serialize and deserialize objects in my projects ( i store the byte array
in a sql server , but just as easy you could write it to a file )


example

<Serializable()> _
Private Structure Selection
Dim ControlSoort As ControlType
Dim Vals As Object
Dim Tooltip As String
Dim Dsc As String
End Structure


Dim vals As Selection = CType(DeSerialize(CType(drH.Item("ControlWrd"),
Byte())), Selection)


where drH.Item("ControlWrd") is the binary data storded in my database , i
have chosen explicitly not to use XML as Binary serialization and
deserialization is
1. more compact 2. much faster 3. i do not want people easy to see what is
stored in the fields


HTH

Michel Posseth
 
Back
Top