Esempio n. 1
0
        private static int MaxWidth(Font font, IEnumerable <String> labels, out string maxString)
        {
            var result    = 0;
            var maxLength = 0;

            maxString = null;
            if (labels != null)
            {
                foreach (var label in labels.Where(l => l != null))
                {
                    // Not strictly guaranteed, but assume that the label with the maximum width
                    // will be within 2 characters of the maximum string length, since actually
                    // measuring everything can be very time consuming
                    if (label.Length + 2 < maxLength)
                    {
                        continue;
                    }
                    maxLength = Math.Max(label.Length, maxLength);
                    int labelWidth = SystemMetrics.GetTextWidth(font, label);
                    if (labelWidth > result)
                    {
                        result    = labelWidth;
                        maxString = label;
                    }
                }
            }
            return(result);
        }
Esempio n. 2
0
        private static int MaxWidth(Font font, IEnumerable <String> labels)
        {
            var result = 0;

            if (labels != null)
            {
                foreach (var label in labels)
                {
                    result = Math.Max(result, SystemMetrics.GetTextWidth(font, label));
                }
            }
            return(result);
        }