Fog Creek Software
Discussion Board




dynamic form generation in .NET

i'm trying to write a windows forms based survey application to be used in a hosiptal emergency room.

A medical researcher has given me about 400 questions for survey in word format. Each question has between 2 or 20 different exclusive choices to answer. Using my maniacal regular expression / perl skillz, I have created an XML file from these word files that describes each survey. The answers are all exclusive checkboxes, so the XML format was easy.

Each question is supposed to be on one screen, with the appropriate answers. I.e. something like "has your child vomited in the past 24 hours?  yes .  no .  i don't know " 
then the surveyee clicks on a button, and gets the next question.

i have figured out how to advance through all my questions using .NEt's wonderful XML manipulation tools. what i am doing right now, is when someone clicks the submit button, i clear the form's controls, add the question text to a label within the form, and then add a radio button for each answer.  this seems to be working ok.

my issue is that i am having a hell of a time making this thing look decent. i am trying to position each radio button underneath the other radio buttons, and it seems to be more work than necessary to have these buttons line up together. the other thing is that if i have a bunch of buttons (say, 12 different choices) the buttons are falling off my form, or piling up on top of one another.  is there any component that will help me automagically resize automatically generated forms so that they always look good?

thanks!

rz
Tuesday, September 02, 2003

note: this is a windows forms app.

rz
Tuesday, September 02, 2003

The Web browser control is great for this sort of stuff.

Take your XML, generate HTML from it, slap it into the browser control, then use the browser's DOM to pull out the item they selected. The browser takes care of all the layout stuff for you.

Chris Tavares
Wednesday, September 03, 2003

Derive the size of a RadioButton based on MeasureString() of the Text. Derive the Size of the GroupBox based on the aggregate sizes of the RadioButtons. Derive the size of the Panel based on the size of the GroupBox. Add the panel to the Form, make sure AutoScroll is set on the form.

Do yourself a favor and get a copy of Petzolds "Programming Microsoft Windows with C#" for this kind of stuff.

Just me (Sir to you)
Wednesday, September 03, 2003

>> "the buttons are falling off my form"

Set the form's AutoScroll property to true then. Or put the radio buttons in a Panel and set the Panel's AutoScroll to true.

Duncan Smart
Wednesday, September 03, 2003

Sounds like a job for XForms. Have a look at http://www.formsplayer.com.

Ryan

Ryan Roberts
Wednesday, September 03, 2003

Interesting how web based applications get critised for their apparent "clunkiness" on this forum. Yet HTML would be make it trivial to generate nice looking resizable forms.

Matthew Lock
Wednesday, September 03, 2003

>Using my maniacal regular expression / perl skillz


Why not do the whole thing in HTML / CGI / Perl?

Or is that not "dotNet"-ish enough?

Matt H.
Wednesday, September 03, 2003

Matthew,

it is the "interaction" that gets all the deserved scorn, not the rendering. Besides, if you are willing to give up pixelperfect control. WinForms can also help you out quite a bit with Panels, Docking and AutoSize, but it is not as advanced as modern HTML in that respect.

Just me (Sir to you)
Wednesday, September 03, 2003

Sure, HTML apps can be a bit of a pain sometimes. There's a lot to be said though for a text based presentation layer which can easily be used to generate GUIs.

Matthew Lock
Wednesday, September 03, 2003

to be honest I am thinking of doing it in HTML/PERL.

the issue is that I have to install this on about 20 laptops, and the data is being collected in ERs that do not have any network connections. I would rather just distribute a single .exe rather than set up perl/webserver/etc on every laptop. I just finished another similar app in .NET, in record time, so I thought .NET would also be a good choice for this project. However the other app i built did not have dynamically changing forms.

I'm pretty good with xml/xslt so i think i am going to try the web control idea first. I'll also take a look at xforms. Thanks for the ideas.

rz
Wednesday, September 03, 2003

actually i'm not going to look at XForms, I thought perhaps you were talking about something else. :-P

rz
Wednesday, September 03, 2003

Um...

You need a standalone .exe?  Then why use .NET?

(I'm not being a smart-*ss.  I've never used .NET.  I just assume you'd use VB, Delphi, etc., if it a quick, visual app.)

Russell Thackston
Wednesday, September 03, 2003

all the laptops are XP and have .NET runtime installed already. the other app i built was a VB.NET app. i'm using it just because it was there, and seemed to be pretty easy. :)

rz
Wednesday, September 03, 2003

I wouldn't spend any time trying to hand-position these different answer choices.  Instead, I'd build a base form that contains all of the common elements (buttons, titles, etc.)  Then, add a panel that will hold all of your radio buttons. 

You can then have a subroutine that takes an array of strings (one string for each possible answer) and converts it into an array of radio buttons that get placed in the correct location in the panel.  If the text for one option might take more than one line, you can account for that with the MeasureString() function. 

If there are too many radio buttons to fit in the panel, it will add scrollbars automatically (with the proper setting.)  Anchor the usercontrol to all four sides of the form so that the user can increase the size of the userform (and thus see more choices) by resizing the form.

This might point you in the right direction:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_vstechart/html/vbtchcreatingcontrolarraysinvisualbasicnetvisualcnet.asp

There's also a really good book by Matthew MacDonald, User Interfaces in VB.Net:Windows Forms and Custom Controls.  (Suitable for C# programmers too, I think.)

Robert Jacobson
Wednesday, September 03, 2003

>Anchor the usercontrol to all four sides of the form so that the user can increase the size of the userform (and thus see more choices) by resizing the form.<

Oops... replace "userform" with "panel."

Robert Jacobson
Wednesday, September 03, 2003

And I'd say to set the docking to fillis even better than anchoring it. Same effect, a little easier to manage.

You can slo use the array of radio buttons idea above and place them into the panel in order, setting each to dock = top. Then they will handle resizing and line wraping without any measurestring interaction on your part.

  --Josh

JWA
Wednesday, September 03, 2003

If you use HTML but don't have a server, you can either insert it into your app (maybe pointless here) or make an HTML app (HTA). Put all the 'logic' in a .NET control or something, have it spit out HTML, then the HTA file can just have a object tag. Or any number of other combinations.

mb
Wednesday, September 03, 2003

RZ if you like Perl there are plenty of ways to get perl running as an exe file. Check out perl2exe http://www.indigostar.com/perl2exe.htm

Matthew Lock
Wednesday, September 03, 2003

You may find this handy too if you want to go with Perl/HTML. It's a little web server that can run CGI scripts on a local machine http://www.indigostar.com/microweb.htm

Matthew Lock
Wednesday, September 03, 2003

*  Recent Topics

*  Fog Creek Home