Wednesday, 31 March 2010

Csharp Layout

Layout routines for C#

I heartily dislike drag and drop form designers. They seem so easy to use but as soon as you need any fine control they let you down. I always liked the simple containers that the Java user interface libraries have that automatically size their contents and arrange them in columns or rows.

So I have decide to create something like it in C#. I originally thought of creating new classes derived from Panel but I think that is is simpler to simply create some functions that take panels and other controls as argument.

Example code will be found in layout.

Row
Add a list of controls to a panel so that they are in left to right order on the screen. Specify the panel first then the left most control, then the rest in order. The function searches the list of controls to discover which has dock=Fill. This must be either the first or the last. The controls are added to the Controls list of the panel either from left to right or from right to left depending on the location of the Fill control. Of course the other controls must have the appropriate DockStyle, Left or Right as appropriate.
Column
As Row except that where Row speaks of Left Column speaks of Top and so on.

Both functions return the panel as their value. This lets us write code that shows the hierrchical structure of the layout. You can then build up the layout piece by piece replacing simple elements with Rows or Columns as you go:

 Column(panelTop, splitterH, panelText); 

You can compile it and check that it works. Now expand it by adding controls to the top panel:

 Column(Row(panelTop, picDotPlot, panelTopRight),  splitterH,  panelText); <example>  The example is intended as preparation for the use of this idea in DotPlot.  <example> Column(Row(panelTop, picDotPlot,  Column(panelTopRight,  buttonGo, frameDotScaling, frameParsing),  splitterH,  Row(panelText,  Column(panelText1, comboFile1, textFile1),  Column(panelText2, comboFile2, textFile2)); 

All the examples assume that the various controls already exist and that all the relevant properties have been set.

Posted via web from kwhitefoot's posterous

No comments:

Post a Comment

Blog Archive

Followers