This is difficult to explain without illustration, so – behold, an illustration, cobbled together from screenshots of a few hello-world examples and a lot of Paint work:

I have started out using Windows Forms on .NET (via IronPython, but that shouldn’t be important), and haven’t been able to figure out very much. GUI libraries in general are very intimidating, simply because every class has so many possible attributes. Documentation is good at explaining what everything does, but not so good at helping you figure out what you need.
I will be assembling the GUI dynamically, but I’m not expecting that to be the hard part. The sticking points for me right now are:
-
How do I get text labels to size themselves automatically to the width of the contained text (so that the text doesn’t clip, and I also don’t reserve unnecessary space for them when resizing the window)?
-
How do I make the vertical scrollbar always appear? Setting the VScroll property (why is this protected when AutoScroll is public, BTW?) doesn’t seem to do anything.
-
How come the horizontal scrollbar is not added by AutoScroll when contents are laid out vertically (via
Dock = DockStyle.Top)? I can use a minimum size for panels to prevent the label and corresponding control from overlapping when the window is shrunk horizontally, but then the scrollbar doesn’t appear and the control is inaccessible. -
How can I put limits on window resizing (e.g. set a minimum width) without disabling it completely? (Just set minimum/maximum sizes for the Form?) Related to that, is there any way to set minimum/maximum widths or heights without setting a minimum/maximum size (i.e. can I constrain the size in only one dimension)?
-
Is there a built-in control suitable for hex editing or am I going to have to build something myself?
… And should I be using something else (perhaps something more capable?) I’ve heard WPF mentioned, but I understand that this involves XML and I really want to build a GUI from XML – I already have data in an object graph, and doing some kind of weird XML pseudo-serialization (in Python, no less!) in order to create a GUI seems incredibly roundabout.
I ended up using WPF.
Getting access to the functionality from IronPython is more involved than I would have expected:
(I’m not sure if I can/should change the version number. The
PublicKeyTokenpresumably has to do with some kind of DLL signing for security purposes; I don’t know why WPF requires this but WinForms didn’t.)Since the namespaces for widgets get quite hairy and there are a lot of names that I want to import, I set up some dynamic import code:
After figuring out the right combination of layout tools (which wasn’t as easy as this summary makes it sound), everything seems to “just work” and I’m quite pleased. The scroll behaviour is accomplished by setting up a
ScrollViewerinside the main window and setting theHorizontalScrollBarVisibilitytoAuto. Inside theScrollViewerI put aStackPanelwhich stacks the “field frames”, each of which is aGridwith two columns (I add two defaultColumnDefinitions to theGrid.ColumnDefinitions). I set the “label” up in column 0, and the “value” widget (combo box, button, whatever) in column 1, with aHorizontalAlignmentofRight.I haven’t set up the nested panels yet, but it seems like it shouldn’t be difficult. I’ve already played around with the system for hooking up events to buttons.