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


C# IFont.GetStringWidth方法代码示例

本文整理汇总了C#中IFont.GetStringWidth方法的典型用法代码示例。如果您正苦于以下问题:C# IFont.GetStringWidth方法的具体用法?C# IFont.GetStringWidth怎么用?C# IFont.GetStringWidth使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IFont的用法示例。


在下文中一共展示了IFont.GetStringWidth方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Truncate

 public string Truncate(string text, IFont font, int width)
 {
     if (font.GetStringWidth(text) > width)
     {
         while ((text.Length > 0) && (font.GetStringWidth(text + "...") > width))
         {
             text = text.Substring(0, text.Length - 1);
         }
         text = text + "...";
     }
     return text;
 }
开发者ID:Skinny1001,项目名称:PlayUO,代码行数:12,代码来源:GSecureTrade.cs

示例2: WrapText

 public static string WrapText(string text, int width, IFont f)
 {
     WrapKey key = new WrapKey(text, width);
     object obj2 = f.WrapCache[key];
     if (obj2 != null)
     {
         return (string) obj2;
     }
     if (f.GetStringWidth(text) <= width)
     {
         f.WrapCache.Add(key, text);
         return text;
     }
     string[] strArray = text.Split(new char[] { ' ' });
     StringBuilder builder = new StringBuilder();
     ArrayList dataStore = GetDataStore();
     for (int i = 0; i < strArray.Length; i++)
     {
         if (f.GetStringWidth(builder.ToString() + strArray[i]) > width)
         {
             if (f.GetStringWidth(strArray[i]) > width)
             {
                 builder.Append(strArray[i]);
                 while ((builder.Length > 1) && (f.GetStringWidth(builder.ToString()) > width))
                 {
                     StringBuilder builder2 = new StringBuilder();
                     builder2.Append(builder[0]);
                     for (int k = 1; k < builder.Length; k++)
                     {
                         if (f.GetStringWidth(builder2.ToString() + builder[k]) > width)
                         {
                             dataStore.Add(builder2);
                             builder = new StringBuilder(builder.ToString().Substring(builder2.Length));
                             continue;
                         }
                         builder2.Append(builder[k]);
                     }
                 }
                 if (i < (strArray.Length - 1))
                 {
                     builder.Append(' ');
                 }
                 continue;
             }
             if (builder.Length > 0)
             {
                 dataStore.Add(builder);
             }
             builder = new StringBuilder(strArray[i]);
             if (i < (strArray.Length - 1))
             {
                 builder.Append(' ');
             }
             continue;
         }
         builder.Append(strArray[i]);
         if (i < (strArray.Length - 1))
         {
             builder.Append(' ');
         }
     }
     if (builder.Length > 0)
     {
         while ((builder.Length > 1) && (f.GetStringWidth(builder.ToString()) > width))
         {
             StringBuilder builder3 = new StringBuilder();
             builder3.Append(builder[0]);
             for (int m = 1; m < builder.Length; m++)
             {
                 if (f.GetStringWidth(builder3.ToString() + builder[m]) > width)
                 {
                     dataStore.Add(builder3);
                     builder = new StringBuilder(builder.ToString().Substring(builder3.Length));
                     continue;
                 }
                 builder3.Append(builder[m]);
             }
         }
         if (builder.Length > 0)
         {
             dataStore.Add(builder);
         }
     }
     StringBuilder builder4 = new StringBuilder();
     int count = dataStore.Count;
     for (int j = 0; j < count; j++)
     {
         builder4.Append(((StringBuilder) dataStore[j]).ToString());
         if (j < (count - 1))
         {
             builder4.Append('\n');
         }
     }
     string str = builder4.ToString();
     f.WrapCache.Add(key, str);
     ReleaseDataStore(dataStore);
     return str;
 }
开发者ID:Skinny1001,项目名称:PlayUO,代码行数:98,代码来源:Engine.cs


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