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):
How to use
Lets say you have a dog entity class:
1 2 3 4 5 6 |
class Dog { public string NameProp { get; set; } public string OwnerProp { get; set; } public bool BarksProp { get; set; } } |
First add the DynForm namespace to your class. Then add the IDynFormEntity interface and the methods required by this interface:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
class Dog : IDynFormEntity { public string NameProp { get; set; } public string OwnerProp { get; set; } public bool BarksProp { get; set; } // Methods and properties required by IDynFormEntity public bool bSaveData { get; set; } public string Validate( string propertyName ) { return ""; } public void SetupFormFields( DynForm.DynForm f ) { } } |
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:
1 2 3 4 5 6 |
public void SetupFormFields( DynForm.DynForm f ) { f.AddLayoutTextBox( "Name", "NameProp" ); f.AddLayoutTextBox( "Owner", "OwnerProp" ); f.AddLayoutCheckbox( "Barks", "BarksProp" ); } |
You also need to make sure the data is valid. Modify the Validate() method like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
public string Validate( string propertyName ) { switch( propertyName ) { case "NameProp": if( this.NameProp == "" ) { return "You must give it a name!"; } break; } return ""; // no errors } |
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:
1 2 3 |
var dog = new Dog(); var f = new DynForm( "Add Dog", dog ); f.ShowDialog(); |
The result looks like this (notice that it does not allow you to save the form, since the name field does not validate):
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.