private static int AllocatedTotalWidth(Size[,] allocation,
int colIndex,
int rowIndex,
int spacingGap)
{
// Find the width of each column
int[] colWidths = AllocatedColumnWidths(allocation, rowIndex);
// Add each column width together
int totalWidth = colWidths[0] + colWidths[1] + colWidths[2];
// If the target column for allocation is empty then an extra
// spacing gap will be required so add it to the total width,
// unless there is nothing at all allocated
if ((totalWidth > 0) && (colIndex >= 0) && (colWidths[colIndex] == 0))
totalWidth += spacingGap;
// Add any required spacing gaps between columns
if ((colWidths[0] > 0) && (colWidths[1] > 0))
totalWidth += spacingGap;
if ((colWidths[1] > 0) && (colWidths[2] > 0))
totalWidth += spacingGap;
if ((colWidths[0] > 0) && (colWidths[1] == 0) && (colWidths[2] > 0))
totalWidth += spacingGap;
return totalWidth;
}