本文整理汇总了C#中System.Windows.Forms.StatusBar.CreateGraphics方法的典型用法代码示例。如果您正苦于以下问题:C# StatusBar.CreateGraphics方法的具体用法?C# StatusBar.CreateGraphics怎么用?C# StatusBar.CreateGraphics使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.StatusBar
的用法示例。
在下文中一共展示了StatusBar.CreateGraphics方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: StatusBarSizeGrip
/// <summary>
/// Initializes a new instance of the <see cref="StatusBarSizeGrip"/> class.
/// </summary>
/// <param name="bar">The status bar.</param>
public StatusBarSizeGrip(StatusBar bar)
{
BorderStyle = StatusBarPanelBorderStyle.None;
Style = System.Windows.Forms.StatusBarPanelStyle.OwnerDraw;
bar.DrawItem += new StatusBarDrawItemEventHandler(bar_DrawItem);
int width = 16;
if (Application.RenderWithVisualStyles)
{
using (Graphics g = bar.CreateGraphics())
{
VisualStyleRenderer renderer = new VisualStyleRenderer(VisualStyleElement.Status.Gripper.Normal);
Size sz = renderer.GetPartSize(g, ThemeSizeType.True);
width = sz.Width;
}
}
int widthT = width + SystemInformation.Border3DSize.Width * 2;
// Can get widthT = 7 (< MinWidth = 10) on Mac Parallels, so we don't want to crash.
Width = widthT >= MinWidth ? widthT : MinWidth;
}
示例2: 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">StatusBar 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
/// </history>
private string TruncateFileName(System.IO.FileInfo file, StatusBar status)
{
const int EXTRA = 20; //used for spacing of the sizer
Graphics g = status.CreateGraphics();
int _strLen = 0;
string _name = file.FullName;
_strLen = Convert.ToInt32(g.MeasureString(_name, status.Font).Width);
if (_strLen >= (status.Width - EXTRA))
{
// truncate to just the root name and the file name (for now)
_name = file.Directory.Root.Name + @"...\" + file.Name;
}
g.Dispose();
return _name;
}