Dynamic content on windows forms

Posted on 2004-10-28
Last Modified: 2012-06-21
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....
Question by:shawl01
    LVL 6

    Accepted Solution

    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
    LVL 6

    Expert Comment

    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
    LVL 2

    Expert Comment

    FYI: There is no information on this solution on how to save the contents of the form.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

     Java Android Coding Bundle

    Whether you're an Apple user or Android addict, learning to code for the Android platform is an extremely valuable, in-demand skill. It all starts with Java, the language behind the apps and games that make Android the top platform it is today.

    Introduction When many people think of the WebBrowser ( control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
    1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
    Want to pick and choose which updates you receive? Feel free to check out this quick video on how to manage your email notifications.
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…

    846 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    5 Experts available now in Live!

    Get 1:1 Help Now