本文整理汇总了C#中System.Windows.Forms.VisualStyles.VisualStyleRenderer.GetTextExtent方法的典型用法代码示例。如果您正苦于以下问题:C# VisualStyleRenderer.GetTextExtent方法的具体用法?C# VisualStyleRenderer.GetTextExtent怎么用?C# VisualStyleRenderer.GetTextExtent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.VisualStyles.VisualStyleRenderer
的用法示例。
在下文中一共展示了VisualStyleRenderer.GetTextExtent方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DrawText
public static void DrawText(IDeviceContext dc, string text, VisualStyleElement element, Font fallbackFont, ref Point location, bool measureOnly, int width)
{
// For Windows 2000, using Int32.MaxValue for the height doesn't seem to work, so we'll just pick another arbitrary large value
// that does work.
Rectangle textRect = new Rectangle(location.X, location.Y, width, NativeMethods.IsWindowsXPOrLater ? Int32.MaxValue : 100000);
TextFormatFlags flags = TextFormatFlags.WordBreak;
if( IsTaskDialogThemeSupported )
{
VisualStyleRenderer renderer = new VisualStyleRenderer(element);
Rectangle textSize = renderer.GetTextExtent(dc, textRect, text, flags);
location = location + new Size(0, textSize.Height);
if( !measureOnly )
renderer.DrawText(dc, textSize, text, false, flags);
}
else
{
if( !measureOnly )
TextRenderer.DrawText(dc, text, fallbackFont, textRect, SystemColors.WindowText, flags);
Size textSize = TextRenderer.MeasureText(dc, text, fallbackFont, new Size(textRect.Width, textRect.Height), flags);
location = location + new Size(0, textSize.Height);
}
}
示例2: GetBodyTextRect
protected override Rectangle GetBodyTextRect(Graphics dc, string text, Rectangle rect)
{
if (IsDefined(VisualStyleElement.ToolTip.Balloon.Normal))
{
VisualStyleRenderer renderer = new VisualStyleRenderer(VisualStyleElement.ToolTip.Balloon.Normal);
return renderer.GetTextExtent(dc, rect, text, TextFormatFlags.Left | TextFormatFlags.WordBreak | TextFormatFlags.VerticalCenter);
}
else
{
SizeF size = dc.MeasureString(text, SystemFonts.DefaultFont, rect.Size.Width,
new StringFormat());
return new Rectangle(new Point(0, 0), Size.Ceiling(size));
}
}
示例3: GetTitleTextRect
protected override Rectangle GetTitleTextRect(Graphics dc, string title, Rectangle rect)
{
if (IsDefined(VisualStyleElement.ToolTip.BalloonTitle.Normal))
{
VisualStyleRenderer renderer = new VisualStyleRenderer(VisualStyleElement.ToolTip.BalloonTitle.Normal);
return renderer.GetTextExtent(dc, rect, title, TextFormatFlags.Left | TextFormatFlags.WordEllipsis | TextFormatFlags.VerticalCenter);
}
else
{
SizeF size = dc.MeasureString(title, new Font(SystemFonts.DefaultFont, FontStyle.Bold), rect.Size.Width,
new StringFormat(StringFormatFlags.NoWrap));
return new Rectangle(new Point(0, 0), Size.Ceiling(size));
}
}
示例4: UpdateTheme
private void UpdateTheme() {
if (_themeElement == null) {
return;
}
using (Graphics g = this.CreateGraphics()) {
_renderer = new VisualStyleRenderer(_themeElement);
Rectangle bounds = new Rectangle(0, 0, this.Width, this.Height);
Rectangle textExtent = _renderer.GetTextExtent(g, bounds, this.Text, TextFormatFlags.Default);
this.Size = this.MinimumSize = new Size(textExtent.Width, textExtent.Height);
}
}
示例5: OnPaint
protected override void OnPaint(PaintEventArgs e)
{
var normal = VisualStyleElement.ToolTip.Standard.Normal;
if (Application.RenderWithVisualStyles && VisualStyleRenderer.IsElementDefined(normal))
{
var renderer = new VisualStyleRenderer(normal);
renderer.DrawBackground(e.Graphics, ClientRectangle);
var textExtent = renderer.GetTextExtent(e.Graphics, ClientRectangle, Text, _tfFlags);
textExtent.X = ClientRectangle.X + ClientRectangle.Width / 2 - textExtent.Width / 2;
textExtent.Y = ClientRectangle.Y + ClientRectangle.Height / 2 - textExtent.Height / 2;
renderer.DrawText(e.Graphics, textExtent, Text, false, _tfFlags);
return;
}
e.Graphics.FillRectangle(SystemBrushes.Info, ClientRectangle);
var pen = SystemInformation.HighContrast ? SystemPens.InfoText : SystemPens.Control;
e.Graphics.DrawLine(pen, ClientRectangle.Left, ClientRectangle.Top, ClientRectangle.Right, ClientRectangle.Top);
e.Graphics.DrawLine(pen, ClientRectangle.Left, ClientRectangle.Top, ClientRectangle.Left, ClientRectangle.Bottom);
e.Graphics.DrawLine(SystemPens.InfoText, ClientRectangle.Left, ClientRectangle.Bottom - 1, ClientRectangle.Right, ClientRectangle.Bottom - 1);
e.Graphics.DrawLine(SystemPens.InfoText, ClientRectangle.Right - 1, ClientRectangle.Top, ClientRectangle.Right - 1, ClientRectangle.Bottom);
var crect = ClientRectangle;
crect.Inflate(-2, -2);
TextRenderer.DrawText(e.Graphics, Text, Font, crect, SystemColors.InfoText, _tfFlags);
}
示例6: method_0
public SizeF method_0(string text)
{
SizeF result;
using (var graphics = CreateGraphics())
{
var normal = VisualStyleElement.ToolTip.Standard.Normal;
if (Application.RenderWithVisualStyles && VisualStyleRenderer.IsElementDefined(normal))
{
var renderer = new VisualStyleRenderer(normal);
var textExtent = renderer.GetTextExtent(graphics, text, TextFormatFlags.Default);
result = renderer.GetBackgroundExtent(graphics, textExtent).Size;
}
else
{
SizeF sizeF = TextRenderer.MeasureText(graphics, text, Font, new Size(SystemInformation.PrimaryMonitorSize.Width, 2147483647), _tfFlags);
sizeF.Width -= 2f;
sizeF.Height += 2f;
result = sizeF;
}
}
return result;
}
示例7: GetBodyRect
public static Rectangle GetBodyRect(IDeviceContext dc, Size minSize, Size maxSize, string text, Rectangle titleRect, ToolTipIcon icon, Padding padding)
{
Rectangle ret;
if (text == null)
{
ret = new Rectangle(new Point(0, 0), minSize);
}
else
{
ret = new Rectangle(new Point(0, 0), maxSize);
ret.Width -= padding.Horizontal;
if (Application.RenderWithVisualStyles)
{
VisualStyleRenderer renderer = new VisualStyleRenderer(VisualStyleElement.ToolTip.Balloon.Normal);
Rectangle rect = renderer.GetTextExtent(dc, ret, text, TextFormatFlags.Left | TextFormatFlags.WordBreak | TextFormatFlags.VerticalCenter);
if (rect.Width + padding.Horizontal > maxSize.Width)
ret.Width = maxSize.Width;
else if (rect.Width + padding.Horizontal < minSize.Width)
ret.Width = minSize.Width;
else
ret.Width = rect.Width;
if (rect.Height > maxSize.Height)
ret.Height = maxSize.Height;
else
ret.Height = rect.Height;
}
else
{
throw new NotImplementedException();
}
}
return ret;
}