Results 1 to 23 of 23

Thread: [2005]Saving/Loading a forms layout.

Threaded View

  1. #1

    Thread Starter
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    [2005]Saving/Loading a forms layout.

    Here's a class I wrote a while ago that uses binary serialization and reflection to serialize all the serializable properties of a form and its child controls to a given stream, this can be any type of stream, such as a filestream or a networkstream.
    It can deserialize from a given stream and apply the property values directly to a form (and the child controls).

    Personally I havent had any use of it but I figured someone might find it interesting...I'll attach it to this post.

    The loading can be sluggish if there are alot of data to read in, altough I am working on making the LoadLayout method asynchronous.

    I havent commented the code in any way unfortunately, so dont hesitate to ask if something looks strange.

    Feel free to comment.

    EDIT: Using the class is pretty straight forward, but I figured I'd add an example:

    To save the forms layout to a file, create a filestream and pass it + the form instance to the SaveLayout method:
    The SaveLayout and LoadLayout methods are both shared so you dont need to create a new instance of the class in order to use them.
    VB.Net Code:
    1. Dim fs As New IO.FileStream("c:\layout.bin", IO.FileMode.Create)
    2.         LayoutSerializer.SaveLayout(Me, fs)
    3.         fs.Close()

    And here's how you'd load it again:
    VB.Net Code:
    1. Dim fs As New IO.FileStream("c:\layout.bin", IO.FileMode.Open)
    2.  
    3.         LayoutSerializer.LoadLayout(Me, fs, LayoutSerializer.LoadMode.DontCreateExistingControls)
    4.         fs.Close()
    Note that I've specified "DontCreateExistingControls" in the LoadLayout call..
    This means that controls that already exist on the form should not be created again, but its property values will still be overwritten with the property values from the loaded layout.
    There are two more LoadMode enums, I think you understand what they do by looking at their names.
    Attached Files Attached Files
    Last edited by Atheist; Feb 4th, 2008 at 01:16 PM.
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width