本文整理汇总了C#中System.Windows.Forms.StatusStrip.CreateGraphics方法的典型用法代码示例。如果您正苦于以下问题:C# StatusStrip.CreateGraphics方法的具体用法?C# StatusStrip.CreateGraphics怎么用?C# StatusStrip.CreateGraphics使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.StatusStrip
的用法示例。
在下文中一共展示了StatusStrip.CreateGraphics方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TruncateFileName
/// <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;
}