本文整理汇总了C#中Media.DrawText方法的典型用法代码示例。如果您正苦于以下问题:C# Media.DrawText方法的具体用法?C# Media.DrawText怎么用?C# Media.DrawText使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Media
的用法示例。
在下文中一共展示了Media.DrawText方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnRender
public override void OnRender(Media.DrawingContext dc)
{
if (_lineCache == null || _lineCache.Count == 0)
{
return;
}
int nLines = _lineCache.Count;
int top = 0;
int width, height;
GetRenderSize(out width, out height);
// Draw each line of Text
//
int lineNumber = _currentLine;
while (lineNumber < nLines)
{
TextLine line = (TextLine)_lineCache[lineNumber];
if (top + line.Height > height)
{
break;
}
TextRun[] runs = line.Runs;
int x;
switch (_alignment)
{
case TextAlignment.Left:
x = 0;
break;
case TextAlignment.Center:
x = (width - line.Width) >> 1; // >> 1 is the same as div by 2
break;
case TextAlignment.Right:
x = width - line.Width;
break;
default:
throw new NotSupportedException();
}
for (int i = 0; i < runs.Length; i++)
{
TextRun run = runs[i];
int w, h;
run.GetSize(out w, out h);
int y = top + line.Baseline - run.Font.Ascent;
dc.DrawText(run.Text, run.Font, run.ForeColor, x, y);
x += w;
}
top += line.Height;
lineNumber++;
}
}