本文整理汇总了C#中SlimDX.MeasureString方法的典型用法代码示例。如果您正苦于以下问题:C# SlimDX.MeasureString方法的具体用法?C# SlimDX.MeasureString怎么用?C# SlimDX.MeasureString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SlimDX
的用法示例。
在下文中一共展示了SlimDX.MeasureString方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WrapMessage
// Calculates wrapping and places in WrappedMessage.
public void WrapMessage(SlimDX.Direct3D9.Font overlayFont, int width)
{
try
{
// Rectangle to store the dimensions in.
Rectangle rect = new Rectangle();
// Measure the sender string.
overlayFont.MeasureString(null, Sender, DrawTextFormat.SingleLine, ref rect);
SenderWidth = rect.Width;
width -= SenderWidth;
// List containing the split lines.
List<String> lines = new List<String>();
// The start index for the measured substring.
int start = 0;
// The length of the measured substring.
int length = 1;
// The last location of a space char.
int lastSpace = -1;
// The current substring.
String text;
// Split the message into lines.
while (start + length - 1 < Content.Length)
{
// Retrieve a substring of the message.
text = Content.Substring(start, length);
// Check if the last char is whitespace.
char c = Content[start + length - 1];
if (c == ' ')
lastSpace = length;
// Measure the substring.
overlayFont.MeasureString(null, text, DrawTextFormat.SingleLine, ref rect);
if (rect.Width > width)
{
// Split the message.
// Attempt to avoid splitting words in the middle.
if (length > 1)
{
if (lastSpace != -1)
length = lastSpace;
else
length--;
}
lines.Add(Content.Substring(start, length));
start += length;
length = 1;
lastSpace = -1;
continue;
}
else if (start + length >= Content.Length)
{
// Add the last line.
lines.Add(text);
break;
}
length++;
}
// Store the lines.
WrappedMessage = lines.ToArray();
// Don't re-attempt the wrapping.
FontUsed = overlayFont;
}
// Don't interrupt the drawing of the other messages.
catch
{
// Do not re-attempt.
WrappedMessage = new String[0];
FontUsed = overlayFont;
}
}