在DOTNET的组件内部文本框/的RichTextbox [英] Components Inside Textbox/RichTextbox in DotNet

查看:112
本文介绍了在DOTNET的组件内部文本框/的RichTextbox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在WPF中的文本/ RichTextBox的部分工作,我需要导入更多的文本框了进去。目前,我使用插入额外的自定义文本框到(他们是必要的,因为它是无法以其他方式做一个表达式)RichTextBox控件。我遇到的问题是我需要集中到文本框中,当光标毗邻richtexbox内的文本框。它似乎忽略该组件并跳过它。没有任何人有一个解决的办法?

I am working with a textbox/richtextbox component in WPF and I need to import additional textboxes into it. Currently, I use a RichTextbox control that inserts additional custom textboxes into (they are necessary since it is an expression that cannot otherwise be done). The problem I'm having is I need to focus into the the textbox when the cursor is adjacent to the textbox inside of the richtexbox. It seems to ignore the component and skip over it. Does anyone else have a solution to this?

我似乎无法得到任何控制光标或RichTexbox内部组件WPF。

I can't seem to get any control to the cursor or components inside of the RichTexbox in WPF.

推荐答案

这是嵌入我的RichTextBox内的UIComponent实际上是一个包含3文本框(基地,上标,下标)数字。我的问题是,光标不能聚焦到数字的组成部分。

The UIComponent that is embedded inside my RichTextBox is actually a digit which contains 3 TextBoxes (base, superscript, and subscript). The problem I had was that the cursor couldn't focus into the digit component.

我一直在寻找的功能是这样的。 。

The function I was looking for is this . . .

RichTextBox.CaretPosition.GetAdjacentElement(LogicalDirection Direction)

下面是我的代码。 。

here is my code . . .

public class MathRichTextbox : RichTextBox
{
    public MathRichTextbox()
    {
        this.PreviewKeyDown += MathRichTextbox_PreviewKeyDown;
    }

    void MathRichTextbox_PreviewKeyDown(object sender, KeyEventArgs e)
    {
        Digit expr = null;

        switch (e.Key)
        {
            case Key.Left:
                expr = findAdjacentMathDigits(LogicalDirection.Backward);
                break;

            case Key.Right:
                expr = findAdjacentMathDigits(LogicalDirection.Forward);                    
                break;
        }

        if (expr != null)
            this.Dispatcher.BeginInvoke(
                new ThreadStart(() => expr.FocusBase()),
                System.Windows.Threading.DispatcherPriority.Input, null);
    }

    private Digit findAdjacentMathDigits(LogicalDirection direction)
    {
        Digit expr = null;

        if (Selection.Text.Length == 0)
        {
            DependencyObject dpObj = CaretPosition.GetAdjacentElement(
                direction);

            // is it contained in BlockUIContainer?
            expr = CaretPosition.GetAdjacentElement(
                direction) as Digit;

            // is it onctained in a InlineUIContainer?
            if (expr == null)
            {
                InlineUIContainer uiWrapper =
                    CaretPosition.GetAdjacentElement(
                    direction) as InlineUIContainer;

                if (uiWrapper != null)
                    expr = uiWrapper.Child as Digit;
            }

        }

        return expr;
    }

}

这篇关于在DOTNET的组件内部文本框/的RichTextbox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆