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


C# IContext.GetTextDimensions方法代码示例

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


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

示例1: Click

 public override void Click(double x, double y, IContext context)
 {
     if (ContainsPoint(x, y))
     {
         if (OnClick != null)
         {
             OnClick();
         }
         Active = true;
     }
     else
     {
         Active = false;
     }
     if (Active == false && Text.Length == 0)
         Text = placeholder;
     if (ContainsPoint (x, y)) {
         if (Active == true && string.Compare (Text, placeholder) == 0)
             Text = "";
         for(int i = 0; i <= Text.Length; i++) {
             if(context.GetTextDimensions (hidden? GetHiddenText().Substring(0, i) : Text.Substring(0, i), Width, Height).X > x - this.X) {
                 cursorPos = i-1;
                 break;
             }
             if (i == Text.Length)
                 cursorPos = i;
         }
     }
 }
开发者ID:anton-christensen,项目名称:p2_software,代码行数:29,代码来源:Inputbox.cs

示例2: DrawWithContext

        public override void DrawWithContext(IContext context, double offsetX, double offsetY)
        {
            Color backupColor = TextColor;
            if (IsDefault ())
                TextColor = placeholderColor;

            if (!hidden)
                base.DrawWithContext (context, offsetX, offsetY);
            else {
                string TextBackup = Text;

                if (Text == placeholder)
                    Text = placeholder;
                else
                    Text = GetHiddenText ();

                base.DrawWithContext (context, offsetX, offsetY);
                Text = TextBackup;
            }
            if (Active) {
                double textWidth = 0;
                if (cursorPos > 0 && Text.Length != 0) {
                    textWidth = context.GetTextDimensions (hidden? GetHiddenText().Substring(0, cursorPos) : Text.Substring (0, cursorPos), Width, Height).X;
                }
                context.DrawLine (new Vector2 (textWidth + offsetX + X + 1, Y + offsetY), new Vector2 (textWidth + offsetX + X + 1, offsetY + Y + Height), new Color (0, 0, 0), 1);
            }
            if (IsDefault ())
                TextColor = backupColor;
        }
开发者ID:anton-christensen,项目名称:p2_software,代码行数:29,代码来源:Inputbox.cs

示例3: KeyPressed

 public override void KeyPressed(string key, IContext context)
 {
     base.KeyPressed(key, context);
     if(Active) {
         switch (key) {
         case "Back":
             if(cursorPos > 0)
                 Text = Text.Remove(--cursorPos, 1);
             break;
         case "Right":
             if (cursorPos < Text.Length)
                 cursorPos++;
             break;
         case "Space":
             Text = Text.Insert (cursorPos, " ");
             cursorPos++;
             break;
         case "Left":
             if (cursorPos > 0)
                 cursorPos--;
             break;
         default:
             if (key.Length == 1) {
                 Text = Text.Insert (cursorPos, key);
                 cursorPos++;
                 if (context.GetTextDimensions (hidden ? GetHiddenText () : Text, Width, Height).X > Width - 5) {
                     KeyPressed ("Back", context);
                 }
             } else {
                 Console.WriteLine ("Unknown key: " + key);
             }
             break;
         }
     }
 }
开发者ID:anton-christensen,项目名称:p2_software,代码行数:35,代码来源:Inputbox.cs


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