Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / June 2007

Tip: Looking for answers? Try searching our database.

Writing/reading control properties to a file

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
John - 24 Jun 2007 16:28 GMT
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
Michel Posseth  [MCP] - 24 Jun 2007 20:27 GMT
i personally would just serialize and deserialize the hole control to disk ,
much easier

regards

Michel

> Hi
>
[quoted text clipped - 20 lines]
>  Next
> Next
John - 24 Jun 2007 21:11 GMT
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

>i personally would just serialize and deserialize the hole control to disk
>, much easier
[quoted text clipped - 27 lines]
>>  Next
>> Next
Michel Posseth  [MCP] - 24 Jun 2007 21:37 GMT
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

> Presumably deserialize requires knowing what object type to expect when
> reading file? My problem is my appe will not know beforehand what objects
[quoted text clipped - 35 lines]
>>>  Next
>>> Next
John - 24 Jun 2007 23:52 GMT
Hi Michael

Is there a code link I can check?

Thanks

Regards

> well  for serializing and deserializing you must at least have an
> interface
[quoted text clipped - 45 lines]
>>>>  Next
>>>> Next
M. Posseth - 25 Jun 2007 08:20 GMT
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

 

> Hi Michael
>
[quoted text clipped - 53 lines]
> >>>>  Next
> >>>> Next
John - 24 Jun 2007 21:33 GMT
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

>i personally would just serialize and deserialize the hole control to disk
>, much easier
[quoted text clipped - 27 lines]
>>  Next
>> Next

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.