示例#1
0
        /// <summary>
        /// Handle  key pressed event
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        void Logic_KeyPressed(object sender, KeyPressedEventArgs args)
        {
            string text = args.PressedKey ?? string.Empty;
            this.CurrentTextBox.Focus();

            if (args.Key is SpecialKey)
            {
                if (args.Key is SpaceKey)
                {
                    text = " ";
                }
                else if (args.Key is TabKey)
                {
                    text = "\t";
                }
                else if (args.Key is EnterKey)
                {
                    if (this.CurrentTextBox.AcceptsReturn)
                        text = "\r\n";
                    else
                    {
            #if !SILVERLIGHT
                        //this.CurrentTextBox.KeyDown(sender, args);
                        this.CurrentTextBox.MoveFocus(new TraversalRequest(FocusNavigationDirection.Next));
                        return;
            #else
            #endif
                    }
                }
                else if (args.Key is BackspaceKey)
                {
                    if (this.CurrentTextBox.Text.Length != 0 &&
                         this.CurrentTextBox.SelectionLength == 0 &&
                         this.CurrentTextBox.SelectionStart != 0)
                    {
                        this.CurrentTextBox.Select(this.CurrentTextBox.SelectionStart - 1, 1);
                    }
                    text = string.Empty;
                }
                else if (args.Key is DeleteKey)
                {
                    if (this.CurrentTextBox.Text.Length != 0 &&
                     this.CurrentTextBox.SelectionLength == 0 &&
                     this.CurrentTextBox.SelectionStart != this.CurrentTextBox.Text.Length)
                    {
                        this.CurrentTextBox.Select(this.CurrentTextBox.SelectionStart, 1);
                    }
                    text = string.Empty;
                }
            }
            // reuse selected text property to do text change
            this.CurrentTextBox.SelectedText = text;
            this.CurrentTextBox.SelectionLength = 0;
            this.CurrentTextBox.SelectionStart = ++this.CurrentTextBox.SelectionStart;
            this.CurrentTextBox.Focus();
        }
示例#2
0
 void activeDefinition_KeyPressed(object sender, KeyPressedEventArgs args)
 {
     // bubble event
     var keyPressedDelegate = KeyPressed;
     if (keyPressedDelegate != null)
     {
         keyPressedDelegate(this, args);
     }
 }