本文整理汇总了C#中System.Windows.Forms.VisualStyles.VisualStyleRenderer.DrawText方法的典型用法代码示例。如果您正苦于以下问题:C# VisualStyleRenderer.DrawText方法的具体用法?C# VisualStyleRenderer.DrawText怎么用?C# VisualStyleRenderer.DrawText使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.VisualStyles.VisualStyleRenderer
的用法示例。
在下文中一共展示了VisualStyleRenderer.DrawText方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Draw
protected override void Draw(Graphics dc, string title, string text, Rectangle rect, Rectangle titleRect, Rectangle bodyRect, Image img, int iconWidth)
{
if (IsDefined(VisualStyleElement.ToolTip.BalloonTitle.Normal) && IsDefined(VisualStyleElement.ToolTip.Balloon.Normal))
{
VisualStyleRenderer titleRenderer = new VisualStyleRenderer(VisualStyleElement.ToolTip.BalloonTitle.Normal);
VisualStyleRenderer balloonRenderer = new VisualStyleRenderer(VisualStyleElement.ToolTip.Balloon.Normal);
balloonRenderer.DrawBackground(dc, rect);
// drawing title
titleRenderer.DrawText(dc,
new Rectangle(Padding.Left + iconWidth, Padding.Top, rect.Width - iconWidth - (Padding.Left + Padding.Right), titleRect.Height),
title, false, TextFormatFlags.Left | TextFormatFlags.WordEllipsis | TextFormatFlags.VerticalCenter);
// drawing text
Rectangle balloonTextBounds = new Rectangle(Padding.Left + iconWidth, Padding.Top + titleRect.Height, rect.Width - iconWidth - (Padding.Left + Padding.Right), rect.Height - (Padding.Top + titleRect.Height + Padding.Bottom));
balloonRenderer.DrawText(dc, balloonTextBounds,
text, false, TextFormatFlags.Left | TextFormatFlags.WordBreak | TextFormatFlags.VerticalCenter);
}
else
{
dc.FillRectangle(SystemBrushes.Info, rect);
dc.DrawRectangle(Pens.Black, new Rectangle(0, 0, rect.Width - 1, rect.Height - 1));
dc.DrawString(title, new Font(SystemFonts.DefaultFont, FontStyle.Bold), SystemBrushes.InfoText,
new PointF(Padding.Left + iconWidth, Padding.Top), new StringFormat(StringFormatFlags.NoWrap));
dc.DrawString(text, SystemFonts.DefaultFont, SystemBrushes.InfoText,
new RectangleF(Padding.Left + iconWidth, Padding.Top + titleRect.Height, bodyRect.Width, bodyRect.Height),
new StringFormat());
}
}
示例2: Draw
public static void Draw(IDeviceContext dc, Size minSize, Size maxSize, string title, string text, Rectangle titleRect, Rectangle rect, ToolTipIcon icon, Padding padding)
{
if (Application.RenderWithVisualStyles)
{
VisualStyleRenderer titleRenderer = new VisualStyleRenderer(VisualStyleElement.ToolTip.BalloonTitle.Normal);
VisualStyleRenderer balloonRenderer = new VisualStyleRenderer(VisualStyleElement.ToolTip.Balloon.Normal);
balloonRenderer.DrawBackground(dc, rect);
if (icon == ToolTipIcon.None)
{
titleRenderer.DrawText(dc, new Rectangle(padding.Left, padding.Top, rect.Width - (padding.Left + padding.Right), titleRect.Height),
title, false, TextFormatFlags.Left | TextFormatFlags.WordEllipsis | TextFormatFlags.VerticalCenter);
Rectangle balloonTextBounds = new Rectangle(padding.Left, padding.Top + titleRect.Height, rect.Width - (padding.Left + padding.Right), rect.Height - (padding.Top + titleRect.Height + padding.Bottom));
balloonRenderer.DrawText(dc, balloonTextBounds,
text, false, TextFormatFlags.Left | TextFormatFlags.WordBreak | TextFormatFlags.VerticalCenter);
}
else
{
throw new NotImplementedException();
}
}
else
{
throw new NotImplementedException();
}
}
示例3: 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);
}
}
示例4: SimpleStyleRenderer_Paint
private void SimpleStyleRenderer_Paint(object sender, PaintEventArgs e)
{
VisualStyleElement element = VisualStyleElement.Button.CheckBox.CheckedNormal;
if (Application.RenderWithVisualStyles &&
VisualStyleRenderer.IsElementDefined(element))
{
VisualStyleRenderer renderer = new VisualStyleRenderer(element);
Rectangle rectCheck = new Rectangle(10, 10, 50, 50);
Rectangle rectBox = new Rectangle(10, 10, 200, 50);
Rectangle rectText = new Rectangle(50, 25, 150, 25);
renderer.DrawBackground(e.Graphics, rectCheck);
renderer.DrawEdge(e.Graphics, rectBox,
Edges.Bottom | Edges.Top | Edges.Left | Edges.Right,
EdgeStyle.Etched, EdgeEffects.Flat);
renderer.DrawText(e.Graphics, rectText, "Styled checkbox", false, TextFormatFlags.Top);
}
else
{
// (Perform ControlPaint drawing here.)
}
}
示例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);
}