当前位置: 首页>>代码示例>>C#>>正文


C# SlimDX.MeasureString方法代码示例

本文整理汇总了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;
                }
            }
开发者ID:bjorngylling,项目名称:Dota2Translator,代码行数:87,代码来源:DXHookD3D9.cs


注:本文中的SlimDX.MeasureString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。