Introducing DynForm, a c# library for semi-automatic WinForms dialogs

Application development often involves creating dialogs where the user is presented a form to enter or edit some sort of data. DynForm aims to make development of this a little bit easier. By implementing a simple interface into your data entities, the DynForm library will be able to semi-automatically build a form and display it to the user to fill in.

Update: You can watch an introduction video to DynForm here, courtesy of Kyle Pew at Webucator.

Source Code

You can download the DynForm source code from GitHub. A sample application is included, showing how to use most features. Everything is written in c#. Both the sample and library code is well documented. It is released as open source, licensed with GPL3.

Screenshots

Here are some example screenshots of what DynForm dialogs can look like (taken from a real application):

dynform3

A typical form for editing person details.

dynform2

When selecting items to add to a list, a separate dialog with filtering options is shown.

dynform1

DynForm can validate data and display both errors and warnings to the user.

How to use

Lets say you have a dog entity class:

First add the DynForm namespace to your class. Then add the IDynFormEntity interface and the methods required by this interface:

DynForm is not fully automatic, so you have to tell it what to show in the form. My goal was to make it fast and easy to use, yet still let the developer be in charge of the design. Modify the  SetupFormFields() method as such:

You also need to make sure the data is valid. Modify the Validate() method like this:

That’s really all you need to do in the entity class itself! Now you are ready to display the form. Add this code, for example in a button press event:

The result looks like this (notice that it does not allow you to save the form, since the name field does not validate):

dynform_example

As you can see, with relatively little code you can easily create forms for a multitude of data entities.

Available Controls

DynForm supports many input controls out of the box:

  • Textbox
  • Masked textbox
  • Checkbox
  • Number spinner
  • Date input
  • Labels & headers
  • Dropdown list
  • Listbox

Listboxes are used for more complex situation. Here the user can add and remove items based on a seprate list of available items. Listboxes can additionally have checkboxes, dropdown lists and text fields associated with each item.

This entry was posted in Development and tagged , , , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *