private void InitializeDisplayElements()
        {
            string[] aNames = null;
            string   columnName;

            lstRunSummaryDisplayElements.Clear();

            for (int i = 0; i < RunSummaryDisplayElementNames.GetLength(0); i++)
            {
                int nSize = RunSummaryDisplayElementNames.GetLength(1);
                if (nSize < 2)
                {
                    continue;
                }

                aNames     = new string[nSize - 1];
                columnName = RunSummaryDisplayElementNames[i, 0];
                for (int j = 0; j < nSize - 1; j++)
                {
                    aNames[j] = String.Empty;
                    aNames[j] = RunSummaryDisplayElementNames[i, j + 1];
                }

                DisplayElement d = new DisplayElement(columnName, aNames);
                lstRunSummaryDisplayElements.Add(d);
            }

            string tableFieldName, displayFieldName;

            lstRunDetailsDisplayElements.Clear();
            for (int i = 0; i < RunDetailsDisplayElementNames.GetLength(0); i++)
            {
                int nSize = RunDetailsDisplayElementNames.GetLength(1);
                if (nSize < 1)
                {
                    continue;
                }
                tableFieldName   = RunDetailsDisplayElementNames[i, 0];
                displayFieldName = RunDetailsDisplayElementNames[i, 1];

                if (string.IsNullOrEmpty(tableFieldName) || string.IsNullOrEmpty(displayFieldName))
                {
                    continue;
                }

                DisplayElement2 d = new DisplayElement2(tableFieldName, displayFieldName);
                lstRunDetailsDisplayElements.Add(d);
            }
        }
        private void AdjustLayout(ReportDocument icryRptDoc)
        {
            if (icryRptDoc == null)
            {
                return;
            }

            bool bAdjust1 = false, bAdjust2 = false, bAdjust3 = false;
            Font theFont;
            int  refWidth = 0;

            for (int i = 0; i < icryRptDoc.ReportDefinition.Sections.Count; i++)
            {
                ReportObjects robjs = icryRptDoc.ReportDefinition.ReportObjects;
                if (robjs == null || robjs.Count == 0)
                {
                    continue;
                }

                for (int j = 0; j < robjs.Count; j++)
                {
                    ReportObject robj = robjs[j];
                    if (robj == null)
                    {
                        continue;
                    }

                    ReportObjectKind robkKind = robj.Kind;
                    if (robkKind == ReportObjectKind.FieldObject && !string.IsNullOrEmpty(robj.Name))
                    {
                        FieldObject fieldObj = (FieldObject)robj;
                        if (fieldObj == null)
                        {
                            continue;
                        }

                        int nIndex = lstRunDetailsDisplayElements.FindIndex(x =>
                        {
                            if ((!string.IsNullOrEmpty(x.DisplayFieldName) && x.DisplayFieldName == fieldObj.Name))
                            {
                                return(true);
                            }
                            return(false);
                        });

                        if (0 <= nIndex)
                        {
                            DisplayElement2 d2 = lstRunDetailsDisplayElements[nIndex];
                            if (d2 != null && !string.IsNullOrEmpty(d2.Name))
                            {
                                float fontSize = d2.EstimateFontSize(d2.Name, new Size(fieldObj.Width / conversionFactor, fieldObj.Height / conversionFactor), fieldObj.Font);
                                if (fontSize > 0.0f && fontSize < fieldObj.Font.Size)
                                {
                                    theFont = new Font(fieldObj.Font.Name, fontSize, fieldObj.Font.Style, fieldObj.Font.Unit);
                                    fieldObj.ApplyFont(theFont);
                                    theFont.Dispose();
                                }
                            }
                            d2.FontSizeAdjusted = true;

                            bool bAllAdjusted = true;
                            foreach (DisplayElement2 de in lstRunDetailsDisplayElements)
                            {
                                if (de == null)
                                {
                                    continue;
                                }

                                bAllAdjusted &= de.FontSizeAdjusted;
                            }

                            bAdjust1 = bAllAdjusted;
                        }
                    }

                    if (robkKind == ReportObjectKind.TextObject && !string.IsNullOrEmpty(robj.Name))
                    {
                        TextObject textObj = (TextObject)robj;
                        if (textObj == null)
                        {
                            continue;
                        }

                        if ((!string.IsNullOrEmpty(textObj.Name) && textObj.Name == "TB_PageFooterCopyright"))
                        {
                            theFont = new Font(textObj.Font.Name, 6.0f, textObj.Font.Style, textObj.Font.Unit);
                            textObj.ApplyFont(theFont);
                            bAdjust2 = true;
                            theFont.Dispose();
                        }
                    }

                    if (robkKind == ReportObjectKind.SubreportObject && !string.IsNullOrEmpty(robj.Name) && robj.Name == "Subreport_RunSummary")
                    {
                        SubreportObject subReportObj = (SubreportObject)robj;
                        ReportDocument  subReportDoc = subReportObj.OpenSubreport(subReportObj.SubreportName);

                        if (subReportDoc == null)
                        {
                            break;
                        }

                        ReportObjects subrobjs = subReportDoc.ReportDefinition.ReportObjects;
                        if (subrobjs == null || subrobjs.Count == 0)
                        {
                            continue;
                        }

                        // Estimate heights
                        for (int m = 0; m < subrobjs.Count; m++)
                        {
                            ReportObject subrobj = subrobjs[m];
                            if (subrobj == null)
                            {
                                continue;
                            }

                            Font font;
                            switch (subrobj.Name)
                            {
                            case "FO_RS_SampleNumber":
                            case "FO_RS_SampleID":
                            case "FO_RS_Protocol":
                            case "FO_RS_SampleVol_mL":
                            case "FO_RS_MagneticParticles":
                            case "FO_RS_Selection_Cocktail":
                            case "FO_RS_Antibody_Cocktail":
                            case "FO_RS_TipRack":
                            case "FO_RS_BufferLotID":
                            case "FO_RS_SampleTube":
                            case "FO_RS_SeparationTube":
                            case "FO_RS_NegativeFractionTube":
                            case "FO_RS_WasteTube":
                                FieldObject fb = (FieldObject)subrobj;
                                font = fb.Font;
                                EstimateHeight(subrobj, font, subrobj.Name);
                                break;
                            }
                        }

                        // Set heights of cells
                        for (int n = 0; n < subrobjs.Count; n++)
                        {
                            ReportObject subrobj = subrobjs[n];
                            if (subrobj == null)
                            {
                                continue;
                            }

                            switch (subrobj.Name)
                            {
                            case "TB_RS_SampleNumber":
                            case "TB_RS_SampleID":
                            case "TB_RS_Protocol":
                            case "TB_RS_SampleVol_mL":
                            case "TB_RS_MagneticParticles":
                            case "TB_RS_Selection_Cocktail":
                            case "TB_RS_Antibody_Cocktail":
                            case "TB_RS_TipRack":
                            case "TB_RS_BufferLotID":
                            case "TB_RS_SampleTube":
                            case "TB_RS_SeparationTube":
                            case "TB_RS_NegativeFractionTube":
                            case "TB_RS_WasteTube":

                                SetHeight(subrobj, subrobj.Name);
                                break;
                            }
                        } // end for
                        for (int n = 0; n < subrobjs.Count; n++)
                        {
                            ReportObject subrobj = subrobjs[n];
                            if (subrobj == null)
                            {
                                continue;
                            }

                            switch (subrobj.Name)
                            {
                            case "TB_RS_SampleVol_mL":
                                refWidth = subrobj.Width;
                                break;

                            case "TB_RS_MagneticParticles":
                            case "TB_RS_Selection_Cocktail":
                            case "TB_RS_Antibody_Cocktail":
                                subrobj.Width = refWidth;
                                break;
                            }
                        } // end for

                        bAdjust3 = true;
                    } // end if sub report

                    if (bAdjust1 && bAdjust2 && bAdjust3)
                    {
                        break;
                    }
                }// end for section object
            }
        }