示例#1
0
        /// <summary>
        /// Truncate the given file's name if it is to long to fit in the given status bar
        /// </summary>
        /// <param name="file">FileInfo object to measure</param>
        /// <param name="status">StatusStrip to measure against</param>
        /// <returns>file name or truncated file name if to long</returns>
        /// <history>
        /// [Curtis_Beard]	   04/21/2006	Created, fixes bug 1367852
        /// [Curtis_Beard]	   03/16/2015	CHG: cleanup variable names and apply using logic
        /// </history>
        private string TruncateFileName(System.IO.FileInfo file, StatusStrip status)
        {
            string name = file.FullName;
             const int EXTRA = 20;     //used for spacing of the sizer
             using (Graphics g = status.CreateGraphics())
             {
            int width = Convert.ToInt32(g.MeasureString(name, status.Font).Width);
            if (width >= (status.Width - EXTRA))
            {
               // truncate to just the root name and the file name (for now)
               name = file.Directory.Root.Name + @"...\" + file.Name;
            }
             }

             return name;
        }