Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


Dynamic content on windows forms

Posted on 2004-10-28
Medium Priority
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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2

Accepted Solution

The_Biochemist earned 2000 total points
ID: 12439192
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

Expert Comment

ID: 12439219
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

Expert Comment

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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

610 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