Saving and retrieving WinForm template info

Discussion in 'Microsoft Dot NET Framework Forms' started by John, Jun 2, 2009.

  1. John

    John Guest

    Hi

    Is there a way to save the following info about controls on a winform to a
    named file and then retrieve them back when needed?

    Control Name, Position on form, Control Binding Info

    The idea is to have different layouts of the controls on the form for
    different users and load appropriate layout/template for a user from file
    when needed.

    Thanks

    Regards
     
    John, Jun 2, 2009
    #1
    1. Advertisements

  2. John,

    Yes with a lot of work and probably very bad maintainable.

    But you can use for that (in sequence of my preference) the registry, an
    isolated storage, an XML file, a CSV file, a INI file maybe even more.

    Cor

    "John" <> wrote in message
    news:...
    > Hi
    >
    > Is there a way to save the following info about controls on a winform to a
    > named file and then retrieve them back when needed?
    >
    > Control Name, Position on form, Control Binding Info
    >
    > The idea is to have different layouts of the controls on the form for
    > different users and load appropriate layout/template for a user from file
    > when needed.
    >
    > Thanks
    >
    > Regards
    >
     
    Cor Ligthert[MVP], Jun 2, 2009
    #2
    1. Advertisements

  3. Hello Cor Ligthert[MVP],

    > John,
    >
    > Yes with a lot of work and probably very bad maintainable.
    >
    > But you can use for that (in sequence of my preference) the registry,
    > an isolated storage, an XML file, a CSV file, a INI file maybe even
    > more.


    The Settings object comes to mind... it even has properties to store information
    on a per user basis and can be used to databind their respective values to
    the controls.

    Probably the least amount of work.


    > "John" <> wrote in message
    > news:...
    >
    >> Hi
    >>
    >> Is there a way to save the following info about controls on a winform
    >> to a named file and then retrieve them back when needed?
    >>
    >> Control Name, Position on form, Control Binding Info
    >>
    >> The idea is to have different layouts of the controls on the form for
    >> different users and load appropriate layout/template for a user from
    >> file when needed.
    >>
    >> Thanks
    >>
    >> Regards
    >>

    --
    Jesse Houwing
    jesse.houwing at sogeti.nl
     
    Jesse Houwing, Jun 2, 2009
    #3
  4. John

    James Hahn Guest

    If you can save the relevant control information in a list of strings you
    can persist it into a string array in user settings. The control name
    should not be saved, as you really need the control to exist before updating
    it with the specific user information recovered from Settings, therefore
    names should be generated according to an internal rule. I just use a
    simple sequential form - User Panel 1, User Panel 2, etc.

    Note that I am assuming you are dealing with one control type - it may be
    possible with different control types, but a lot more complex. I can
    therefore put each control in an array of controls (I have used A() in this
    example) instead of referring to them through Me.Controls(). This means I
    can access the controls by array index in A(), so I don't need to know the
    names, and it means that there is no problem dealing with a variable number
    of controls. My control is actually a user control (UserPanel) that
    consists of a number of standard controls.

    Set up your Settings storage like this - one for each property you need to
    save.

    User Setting Name - whatever (eg PANELTOPS)
    User Setting Type - System.Collections.SpecializedStringCollection
    User Setting Scope - User
    User Setting Value -
    <?xml version="1.0" encoding="utf-16"?>
    <ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <string>25</string>
    </ArrayOfString>

    (25 is the actual default setting - change to your required default for each
    particular list)

    Then access it using code like the following:
    'At Class level
    Dim a As New List(Of UserPanel) 'Array of user panels.

    'To save the Top of each control on a form:
    Dim sp As New System.Collections.Specialized.StringCollection()
    For N As Integer = 0 To A.Count - 1
    sp.Add(A.(N).Location.Y.Tostring)
    Next
    My.Settings.PANELTOPS = sp
    For N As Integer = 0 To A.Count - 1
    sp.Add(A.(N).Location.X.Tostring)
    Next
    My.Settings.PANELLEFTS = sp
    'etc
    My.Settings.Save()

    'To Retrieve and set the location of each control on a form
    Dim UP as New UserPanel
    Dim sp As New System.Collections.Specialized.StringCollection()
    sp = My.Settings.PANELTOPS
    For N As Integer = 0 To My.Settings.PANELTOPS.Count- 1
    me.Controls.Add(UP)
    a.add(UP)
    'Other initialisation code for UP goes here
    a(N).Location.Y = Val(sp(N))
    Next
    For N As Integer = 0 To My.Settings.PANELLEFTS.Count- 1
    sp = My.Settings.PANELLEFTS
    a(N).Location.X = Val(sp(N))
    Next
    'etc.

    "John" <> wrote in message
    news:...
    > Hi
    >
    > Is there a way to save the following info about controls on a winform to a
    > named file and then retrieve them back when needed?
    >
    > Control Name, Position on form, Control Binding Info
    >
    > The idea is to have different layouts of the controls on the form for
    > different users and load appropriate layout/template for a user from file
    > when needed.
    >
    > Thanks
    >
    > Regards
    >
     
    James Hahn, Jun 7, 2009
    #4
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Marc Scheuner

    Saving the "restored" winform size

    Marc Scheuner, Jul 4, 2003, in forum: Microsoft Dot NET Framework Forms
    Replies:
    5
    Views:
    2,025
    Ian Cooper
    Jul 17, 2003
  2. Guest

    Saving a WinForm and its controls properties from run to run

    Guest, Dec 18, 2003, in forum: Microsoft Dot NET Framework Forms
    Replies:
    1
    Views:
    199
  3. arkam

    Winform with background image and transparent usercontrols

    arkam, Jan 26, 2004, in forum: Microsoft Dot NET Framework Forms
    Replies:
    0
    Views:
    1,355
    arkam
    Jan 26, 2004
  4. Joerg Krause

    WinForm App and TaskManager

    Joerg Krause, Feb 27, 2004, in forum: Microsoft Dot NET Framework Forms
    Replies:
    1
    Views:
    273
    Ying-Shen Yu[MSFT]
    Feb 28, 2004
  5. Bill Gower

    .Net Winform saving a file to local drive

    Bill Gower, Jul 17, 2007, in forum: Microsoft Dot NET Framework Forms
    Replies:
    1
    Views:
    204
    AlexS
    Jul 17, 2007
Loading...

Share This Page