コード例 #1
0
 public GUCView AddChild(GUCView view)
 {
     children.Add(view);
     return(view);
 }
コード例 #2
0
        public void KeyPressed(VirtualKeys key)
        {
            if (!enabled)
            {
                return;
            }

            if (key == VirtualKeys.Back) //Backspace, delete char behind the cursor
            {
                if (cursorPos > 0)
                {
                    _Input.Remove(cursorPos - 1, 1);
                    cursorPos--;
                }
            }
            else if (key == VirtualKeys.Delete) //delete char in front of cursor
            {
                if (_Input.Length > cursorPos)
                {
                    _Input.Remove(cursorPos, 1);
                }
            }
            else if (key == VirtualKeys.Left)
            {
                if (cursorPos > 0)
                {
                    cursorPos--;
                }
            }
            else if (key == VirtualKeys.Right)
            {
                if (_Input.Length > cursorPos)
                {
                    cursorPos++;
                }
            }
            else
            {
                if (_Input.Length > CharacterLimit)
                {
                    return;
                }

                string str = GetCharFromKey(key);
                if (string.IsNullOrEmpty(str))
                {
                    return;
                }

                char c = str[0];
                if (!GUCView.GothicContainsChar(c)) //check if typed char is supported by gothic's font
                {
                    return;
                }

                if (OnlyNumbers && !char.IsNumber(c))
                {
                    return;
                }

                if (!AllowSpaces && char.IsWhiteSpace(c))
                {
                    return; //we don't want spaces
                }
                if (!AllowSymbols && char.IsSymbol(c))
                {
                    return;
                }

                if (fixedBorders && StringPixelWidth(Input) + GUCView.GetCharWidth(c) > width) //check if fixed borders are reached
                {
                    return;
                }

                //Allow inherited classes to manipulate or decline the input char before adding it.
                if (OnCharInput(c, out c))
                {
                    _Input.Insert(cursorPos, c);
                    cursorPos++;
                }
            }
            cursorVis.Show();
            UpdateInputVisual();
        }