本文整理汇总了C#中System.Windows.Forms.VisualStyles.VisualStyleRenderer.GetBackgroundExtent方法的典型用法代码示例。如果您正苦于以下问题:C# VisualStyleRenderer.GetBackgroundExtent方法的具体用法?C# VisualStyleRenderer.GetBackgroundExtent怎么用?C# VisualStyleRenderer.GetBackgroundExtent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.VisualStyles.VisualStyleRenderer
的用法示例。
在下文中一共展示了VisualStyleRenderer.GetBackgroundExtent方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnPaint
/// ------------------------------------------------------------------------------------
/// <summary>
///
/// </summary>
/// ------------------------------------------------------------------------------------
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaintBackground(e);
if (m_fParentIsToolstrip)
{
PaintOnToolbar(e);
return;
}
if (!Application.RenderWithVisualStyles)
ControlPaint.DrawBorder3D(e.Graphics, ClientRectangle, Border3DStyle.Sunken);
else
{
VisualStyleRenderer renderer;
renderer = new VisualStyleRenderer(Enabled ?
VisualStyleElement.TextBox.TextEdit.Normal :
VisualStyleElement.TextBox.TextEdit.Disabled);
renderer.DrawBackground(e.Graphics, ClientRectangle, e.ClipRectangle);
// When the textbox background is drawn in normal mode (at least when the
// theme is one of the standard XP themes), it's drawn with a white background
// and not the System Window background color. Therefore, we need to create
// a rectangle that doesn't include the border. Then fill it with the text
// box's background color.
Rectangle rc = renderer.GetBackgroundExtent(e.Graphics, ClientRectangle);
int dx = (rc.Width - ClientRectangle.Width) / 2;
int dy = (rc.Height - ClientRectangle.Height) / 2;
rc = ClientRectangle;
rc.Inflate(-dx, -dy);
using (SolidBrush br = new SolidBrush(txtScrRef.BackColor))
e.Graphics.FillRectangle(br, rc);
}
}
示例2: 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;
}