示例#1
0
        /// <summary>
        /// 双击项时显示编辑框
        /// </summary>
        private void LBox_DoubleClick(object sender, EventArgs e)
        {
            if (LBox.Items.Count != 0)
            {
                int    itemSelected = LBox.SelectedIndex;
                string itemText     = LBox.Items[itemSelected].ToString();

                Rectangle rect = LBox.GetItemRectangle(itemSelected);
                txtEdit.Parent    = LBox;
                txtEdit.Bounds    = rect;
                txtEdit.Multiline = true;
                txtEdit.Visible   = true;
                txtEdit.Text      = itemText;
                txtEdit.Focus();
                txtEdit.SelectAll();
            }
        }
示例#2
0
        private void txt_PreviewKeyDown(object sender, KeyEventArgs e)
        {
            RichTextBox R = sender as RichTextBox;


            var position = R.CaretPosition.GetCharacterRect(LogicalDirection.Forward);


            if (LBox != null)
            {
                LBox.SetValue(Canvas.LeftProperty, position.X);
                LBox.SetValue(Canvas.TopProperty, position.Y + 25);
            }

            switch (e.Key)
            {
            case Key.Space:
                showlist();
                e.Handled = true;
                // LBox.Focus();
                break;

            case Key.Up:
                if (LBox.Visibility == Visibility.Visible)
                {
                    LBox.SelectedIndex = (LBox.SelectedIndex < 1) ? 0 : LBox.SelectedIndex - 1;
                }
                e.Handled = true;

                break;

            case Key.Down:
                if (LBox.Visibility == Visibility.Visible)
                {
                    LBox.SelectedIndex = (LBox.Items.Count == LBox.SelectedIndex + 1) ? LBox.Items.Count - 1 : LBox.SelectedIndex + 1;
                }
                e.Handled = true;

                break;
            //LBox.Focus();


            case Key.Enter:
                if (MyStructureString.IsComplete)
                {
                    myParagraph = new Paragraph();
                    txt.Document.Blocks.Add(myParagraph);
                    MyStructureString.Clear();

                    //txt.CaretPosition = txt.CaretPosition.DocumentEnd;
                    e.Handled = true;
                }
                else
                {
                    e.Handled = true;
                }
                break;

            case Key.Tab:
                if (LBox.SelectedIndex >= 0)
                {
                    MyStructureString.Append(LBox.SelectedItem.ToString().TrimEnd());
                    myParagraph.Inlines.Clear();
                    myParagraph.Inlines.AddRange(MyStructureString.Spans);
                    txt.CaretPosition = txt.CaretPosition.DocumentEnd;

                    LBox.SelectedItem = null;
                    //  txt.Focus();
                    LBox.Visibility = Visibility.Hidden;

                    // txt.Focus();
                }
                e.Handled = true;
                break;


            case Key.Escape:
                LBox.Visibility = Visibility.Hidden;
                break;

            case Key.Back:
                LBox.Visibility = Visibility.Hidden;
                e.Handled       = true;
                string cur = (new TextRange(txt.Document.ContentStart, txt.Document.ContentEnd).Text).TrimEnd();
                if (cur != string.Empty)
                {
                    cur = cur.Substring(0, cur.Length - 1);
                    MyStructureString.Clear();
                    MyStructureString.Append(cur);
                    myParagraph.Inlines.Clear();
                    myParagraph.Inlines.AddRange(MyStructureString.Spans);
                    txt.CaretPosition = txt.CaretPosition.DocumentEnd;
                }
                break;


            default:
                //txt.Focus();
                showlist();
                e.Handled = true;
                break;
            }

            //e.Handled = true;
        }