Dynamic Dialogs

Roland Weigelt in a recent blog entry talks about having to spend too much time on producing relatively simple dialogs.  In the past, I found myself thinking about this too, mainly because I wanted a dialog (GUI) alternative to providing arguments on the command line.

I thought of writing a simple dialog editor, but soon realized that essentially all the (script) dialogs I needed to produce looked the same - they have one or more controls and labels in a vertical format like the one below.

Having a single dynamic dialog class would enable me to use Alintex Script's automatic inheritance mechanism to consume and reuse such a dynamic dialog class across multiple scripts.

So I produced a DynamicDialog class (in C#) which allows the dialog above to be displayed with the following code (in this case in late bound VB.NET):-

dlg = new DynamicDialog(4)
dlg.ShowDialog

Or with more useful text labels:-

dlg = new DynamicDialog("From", "Password", "To", "Message", "Confirm")
dlg.Title = "Send Message"
dlg.ShowDialog

Or even more useful perhaps...

dlg = new DynamicDialog("From", "Password", "To", "Message", "Confirm", "Type")
dlg.Title = "Send Message"

dlg.SetControl("Password", new PasswordControl)
dlg.SetControl("Message", new MemoControl)
dlg.SetControl("Confirm", new CheckControl)
dlg.SetControl("Type", new ComboControl("Comment", "Suggestion", "Other"))

dlg.ShowDialog

You can retrieve the entered value of any control by “name” or index.  In other words, both of the following lines produce the same result.

result = dlg(“Message“)
result = dlg(4)

You can set default values for controls in a similar way.

dlg("To") = "Alex Hoffman"
dlg("Confirm") = True

All controls in the DynamicDialog implement a custom IDynamicControl interface which abstracts the “result” from different control types.  This provides an extensible method of adding new controls.  Tooltips are also supported.

Users of Alintex Script can view the public interface by right clicking on the “dynamicDialog.cs” file in Windows Explorer, right-clicking, and choosing “Display Public Script Interface”

An example script which uses (and includes) dynamicDialog.cs can be downloaded here.

Once unzipped, you can simply double click on the file (testDialog.psf) to execute the script, or type axwscript testdialog.psf on the command line.  Information on PSF script files is available here.

Feel free to use or adapt the dynamicDialog.cs code to your needs.

2 Comments

Comments have been disabled for this content.