ACAT.Extensions.Default.FunctionalAgents.FileBrowserAgent.FileBrowserScanner.getMeasuredString C# (CSharp) Method

getMeasuredString() private method

Returns string that graphically fits into the specified width. If it doesn't, curtails the string and adds ellipses
private getMeasuredString ( Graphics graphics, Font font, int width, String inputString ) : String
graphics Graphics Graphics object used to mesaure width of string
font System.Drawing.Font font to use
width int width to fit in
inputString String input string
return String
        private String getMeasuredString(Graphics graphics, Font font, int width, String inputString)
        {
            int chop = 5;

            var str = inputString;

            try
            {
                while (true)
                {
                    SizeF sf = graphics.MeasureString(str, font);

                    if (sf.Width > width * ScannerCommon.PositionSizeController.ScaleFactor)
                    {
                        str = inputString.Substring(0, inputString.Length - chop) + "...";
                        chop += 5;
                    }
                    else
                    {
                        break;
                    }
                }
            }
            catch
            {
                str = inputString;
            }

            return str;
        }