Monday, August 29, 2005 - 14:52

Windows Forms Layouts

I've been working with forms in .net lately, and there are a couple of real deficiencies. I think some of them may have been fixed in 2.0, but unfortunately there are lot of us still using the older version!

The most annoying thing is that you can't zoom in or out of the form that you're editing in the designer. It's fine if you're only creating a small form, but if you're working on a large form you need to keep scrolling around to see the various parts. Sure, you can close some of the extraneous windows (such as the Solution Explorer), and even some of the necessary windows (such as the toolbox), but it's just not enough. Why not have a zoom control like most image editing packages?

It would also be really useful to be able dock or anchor controls to each other, rather than only to the edge of the form. I think that this has improved in 2.0, although maybe not in this exact way. And a less buggy docking system would be great... currently, I'm trying to design a form with various controls on it so that some of the controls (checkedlistboxes) expand horizontally and vertically when the form is maximized. This involves lots and lots of panels, anchoring, and docking! Each control (together with its label) has to go on its own panel, anchored appropriately, and those panels need to be grouped into other panels - each subpanel must be docked correctly within its parent panel. And then depending on how complicated the form is (which isn't very: a simple 2 x 2 layout, maybe a 3 x 2 in some cases), those panels need to be docked within another panel. And then you need a resize event handler for each containing panel, to resize the inner panels appropriately - see this Code Project article for a simple example.

And this is finicky enough, but it's even worse when the panels refuse to dock correctly. The order in which you dock controls is very important, and sometimes not intuitive. In this case, I have three vertical panels - the left should dock to the left, the right to the right, and the middle should fill the available space. But if I dock left to left, then right to right, then middle to fill, the middle panel takes up the left panel's space! No matter what order I set the docking in, it just won't work. And if I dock the middle panel to the right, it docks to the right of the form, not to the left edge of the right-docked panel. In this case, anyway ... in other situations, that's worked okay.

Aarrrgh.

Update: It turns out that while setting the docking in the right order is important, what is even more important is the order in which the controls are instantiated. You know that code generated by the designer that you're not supposed to edit? Well, if your docking isn't working correctly, you may need to edit it. For example, I have a label docked the top of the form, and a datagrid also docked to the top, but I want the label docked above the grid, and the top of the grid essentially docked to the bottom of the label. It was working on one form, but not on the other - the difference was that the grid had to be instantiated *before* the label.

Labels:

0 Comments:

Post a Comment

<< Home