By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,677 Members | 1,280 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,677 IT Pros & Developers. It's quick & easy.

Writing/reading control properties to a file

P: n/a
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
Jun 24 '07 #1
Share this Question
Share on Google+
6 Replies


P: n/a
i personally would just serialize and deserialize the hole control to disk ,
much easier

regards

Michel
"John" <Jo**@nospam.infovis.co.ukschreef in bericht
news:%2****************@TK2MSFTNGP04.phx.gbl...
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

Jun 24 '07 #2

P: n/a
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

"Michel Posseth [MCP]" <MS**@posseth.comwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
>i personally would just serialize and deserialize the hole control to disk
, much easier

regards

Michel
"John" <Jo**@nospam.infovis.co.ukschreef in bericht
news:%2****************@TK2MSFTNGP04.phx.gbl...
>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


Jun 24 '07 #3

P: n/a
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

"Michel Posseth [MCP]" <MS**@posseth.comwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
>i personally would just serialize and deserialize the hole control to disk
, much easier

regards

Michel
"John" <Jo**@nospam.infovis.co.ukschreef in bericht
news:%2****************@TK2MSFTNGP04.phx.gbl...
>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


Jun 24 '07 #4

P: n/a
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
"John" <Jo**@nospam.infovis.co.ukschreef in bericht
news:%2****************@TK2MSFTNGP05.phx.gbl...
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

"Michel Posseth [MCP]" <MS**@posseth.comwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
>>i personally would just serialize and deserialize the hole control to disk
, much easier

regards

Michel
"John" <Jo**@nospam.infovis.co.ukschreef in bericht
news:%2****************@TK2MSFTNGP04.phx.gbl...
>>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



Jun 24 '07 #5

P: n/a
Hi Michael

Is there a code link I can check?

Thanks

Regards

"Michel Posseth [MCP]" <MS**@posseth.comwrote in message
news:um*************@TK2MSFTNGP05.phx.gbl...
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
"John" <Jo**@nospam.infovis.co.ukschreef in bericht
news:%2****************@TK2MSFTNGP05.phx.gbl...
>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

"Michel Posseth [MCP]" <MS**@posseth.comwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
>>>i personally would just serialize and deserialize the hole control to
disk , much easier

regards

Michel
"John" <Jo**@nospam.infovis.co.ukschreef in bericht
news:%2****************@TK2MSFTNGP04.phx.gbl.. .
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



Jun 24 '07 #6

P: n/a
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

"John" wrote:
Hi Michael

Is there a code link I can check?

Thanks

Regards

"Michel Posseth [MCP]" <MS**@posseth.comwrote in message
news:um*************@TK2MSFTNGP05.phx.gbl...
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
"John" <Jo**@nospam.infovis.co.ukschreef in bericht
news:%2****************@TK2MSFTNGP05.phx.gbl...
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

"Michel Posseth [MCP]" <MS**@posseth.comwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
i personally would just serialize and deserialize the hole control to
disk , much easier

regards

Michel
"John" <Jo**@nospam.infovis.co.ukschreef in bericht
news:%2****************@TK2MSFTNGP04.phx.gbl...
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




Jun 25 '07 #7

This discussion thread is closed

Replies have been disabled for this discussion.