Dynamic content on windows forms

I need to build a windows application that is to be used in a disconnected network enviroment.  I need the ability to be able to add new forms/layouts into the application after it has been compiled and installed on the target pc's (xp tablet).

The form layouts will each need to contain some logic to sense check the information entered.

I have had the following ideas on how the forms could be added but I do not know if this is actually possible:

1) Form constructed from a local DB (Access or XML) which can be sync'd with a central server once a day.
2) Forms are contained within DLL's that can be sync'd with a central server once a day and can be bound at runtime
3) Forms are saved as individual files to local HD and loaded at runtime when required (like a crystal report but with a form)

The data captured by the forms will be saved out to a local DB (prob. XML file) and uploaded to central servers once a day when connected to network (I don't need help with this bit, but include it to give you an overview of what I am trying to achieve)

Many thanks in advance....
Who is Participating?
I had recently done a very similar project by the sounds of things...

1) I used an XML file to store the form settings and also all of the information on the controls.

It was structured as below:

<?xml version="1.0" encoding="utf-8" ?>
<Form Name="frmDynamic Height="480 Width="640 BackColor="AliceBlue Title="My Dynamic Form" ............  ></Form>
<TextBox Name="txtInputUsername" Top="5" Left="15" Handler="TextChangedValidator" Font="Verdana" Password="False".......></TextBox>
<TextBox Name="txtInputPassword" Top="25" Left="15" Handler="TextChangedValidator" Font="Verdana" Password="True".......></TextBox>
<Button Name="btnClear" Top="45" Left="15" Handler="btnClearClickedHandler" FlatStyle="Flat"......></Button>
<Button Name="btnValidate" Top="45" Left="35" Handler="btnClearClickedHandler" FlatStyle="Flat"......></Button>

Now the file should contain information for every control and all of their properties that you want to set

2) Parse the xml file with loops, simple nesting of select cases and a sprinkling of 'ifs'

e.g. this will set the properties on teh form and also create new textbox controls... Just customise it for the controls and properties you want (It should basically work as is just needs some polishing and finnishing off.

            'Dimension the XML Reader and storage variables
            Dim xmlReader As System.Xml.XmlTextReader
            'Instantiate the reader and locate file
            xmlReader = New System.Xml.XmlTextReader("C:\Test.xml") 'Alter filename to suit
            'Get the reader to parse all of the records and select the name of the elements you want
            Do While xmlReader.Read
                Select Case xmlReader.Name
                    'if it finds an element called Form
                Case "Form"
                        'check that the reader has attributes (VALUE="x") and loop through them setting the forms attributes
                        If xmlReader.HasAttributes Then
                            Do While xmlReader.MoveToNextAttribute
                                Select Case xmlReader.Name
                                    Case "Name"
                                        Me.Name = xmlReader.Value
                                    Case "Title"
                                        Me.Text = xmlReader.Value
                                    Case "Height"
                                        Me.Height = CType(xmlReader.Value, Integer)
                                    Case "Width"
                                        Me.Width = CType(xmlReader.Value, Integer)
                                    Case "BackColor"
                                End Select
                        End If
                        'find an element named textbox
                    Case "TextBox"
                        Dim txtbx As New TextBox
                        'check it has attributes and then create a new textbox before
                        'setting its properties using select cases for the attributes
                        If xmlReader.HasAttributes Then
                            Do While xmlReader.MoveToNextAttribute
                                Select Case xmlReader.Name
                                    Case "Name"
                                        txtbx.Name = xmlReader.Value
                                    Case "Text"
                                        txtbx.Text = xmlReader.Value
                                    Case "Height"
                                        txtbx.Height = CType(xmlReader.Value, Integer)
                                    Case "Width"
                                        txtbx.Width = CType(xmlReader.Value, Integer)
                                    Case "Top"
                                        txtbx.Top = CType(xmlReader.Value, Integer)
                                    Case "Password"
                                        If xmlReader.Value = True Then
                                            txtbx.PasswordChar = "*"
                                        End If
                                    Case "Handler"
                                        '..... add any other attributes to map to properties
                                End Select
                                'add teh control to your form
                        End If
                End Select
                'loop to next element
            'close the reader and release the file
        Catch ex As Exception

        End Try

Hope it helps
P.S. the above code can go either in the new, form_load or even the onclick event of a control already present on the form for example.

P.S. you don't need to store individual forms per se just a collection of these xml files and also if there are control common to all of the forms then just place them in the correct place on the blank form and just add in the ones which need to be truly dynamic
FYI: There is no information on this solution on how to save the contents of the form.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.