/// <summary> Adds a new block to this form. </summary> /// <returns> Returns the instance. </returns> public Block AddBlock(FormColumnLayout layout) { Block block = new Block(layout); this.Blocks.Add(block); return(block); }
/// <summary> Constructs a new block. </summary> public Block(FormColumnLayout layout) { Visible = true; this.FormColumnLayout = layout; this.Columns = new List <Column>(); }
//=== Elements /// <summary> Set layout. </summary> public void SetLayout(FormColumnLayout layout) { // 1. Fetch all existing elements into single list IList <FormElement> fElements = new List <FormElement>(); if (Columns != null) { Columns.ForEach(x => { if (x.Elements != null) { fElements = fElements.Concat(x.Elements).ToList(); } }); } // 2. Create new column layout for this Block this.Visible = true; this.FormColumnLayout = layout; this.Columns.Clear(); //this.Columns = new List<Column>(); int columnCount = GetColumnCount(); for (int i = 0; i < columnCount; i++) { Columns.Add(new Column { Number = i + 1 }); } // 3. Distribute all elements per column (vertical layout) int cElements = fElements.Count; int maxElements = Convert.ToInt32(Math.Ceiling(Convert.ToDouble(cElements) / Convert.ToDouble(columnCount))); int eIndex = 0; for (int i = 1; i <= columnCount; i++) { Column column = Columns.First(x => x.Number == i); for (int j = 1; (j <= maxElements && eIndex < cElements); j++) { column.Elements.Add(fElements[eIndex]); eIndex++; } } }