RichTextbox数学函数 [英] RichTextbox math function

查看:59
本文介绍了RichTextbox数学函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是尝试编写用于数学绘图的wfp应用程序.该应用程序将 实时 在RichTextbox中输入 x2 时为上标.就像这样 网络 .我的问题是: 

I am attempting to write a wfp application for math graphing. This application will real-time superscript when input x2 in RichTextbox. Just like this web .My problem is : 

  1. 我只能为第一个x 2
  2. 加上上标style ="font-size:0.75em; line-height:1.5">"x2"不仅会抄袭 2
  3. 如何
  1. I can only superscript the first x2
  2. The "x2" will supercript not only 2
  3. How to real-time Fraction

这是我的代码.

谢谢

void Function1_TextChanged(object sender, TextChangedEventArgs e) { string inputData = new TextRange(this.Function1.Document.ContentStart, this.Function1.Document.ContentEnd).Text; this.Function1.TextChanged -= Function1_TextChanged; DrawFunction(1, inputData); //graphing MySuperscript(Function1, inputData); this.Function1.TextChanged += Function1_TextChanged; }

void MySuperscript(RichTextBox richTextBox, string inputData)
{
    TextPointer tp = richTextBox.Document.ContentStart;

    Regex regex = new Regex(@"[a-zA-Z][2]", RegexOptions.None);
    foreach (Match match in regex.Matches(inputData))
        if (match.Success)
        {
            int indexInRun = inputData.IndexOf(match.Value);
            if (inputData.Substring(indexInRun + 1, 1) == "2")
            {
                richTextBox.Selection.Select(tp.GetPositionAtOffset(indexInRun + 3), tp.GetPositionAtOffset(indexInRun + 4));

                if ((BaselineAlignment)richTextBox.Selection.GetPropertyValue(Inline.BaselineAlignmentProperty) != BaselineAlignment.Superscript)
                {
                    richTextBox.Selection.ApplyPropertyValue(Inline.BaselineAlignmentProperty, BaselineAlignment.Superscript);

                    richTextBox.Selection.Select(richTextBox.Document.Blocks.FirstBlock.ContentEnd, richTextBox.Document.Blocks.FirstBlock.ContentEnd);
                    richTextBox.Selection.ApplyPropertyValue(Inline.BaselineAlignmentProperty, BaselineAlignment.Baseline);
                    richTextBox.AppendText(" ");
                }
                else
                    richTextBox.Selection.Select(richTextBox.Document.Blocks.FirstBlock.ContentEnd, richTextBox.Document.Blocks.FirstBlock.ContentEnd);                
            }                    
        }
            
}

推荐答案

我修复了上标.但是我不知道 Fraction

这是我的真实-时间上标代码

void Function1_TextChanged(object sender, TextChangedEventArgs e)
{
    string inputData = new TextRange(this.Function1.Document.ContentStart, this.Function1.Document.ContentEnd).Text;

    this.Function1.TextChanged -= Function1_TextChanged;
    DrawFunction(1, inputData);
    MySuperscript(Function1, inputData);
    this.Function1.TextChanged += Function1_TextChanged;
}

void MySuperscript(RichTextBox richTextBox, string inputData)
{
    TextPointer tp = richTextBox.Document.ContentStart;

    Regex regex = new Regex(@"[a-zA-Z][2]", RegexOptions.None); 
    if (regex.IsMatch(inputData))
    {
        this.focusFunction.Document.Blocks.Clear(); 
        this.focusFunction.Document.Blocks.Add(new Paragraph());
        Paragraph p = focusFunction.Document.Blocks.FirstBlock as Paragraph;
        p.FontFamily = new System.Windows.Media.FontFamily("Palatino Linotype"); 
        Run r = new Run(regex.Split(inputData)[0].Trim());

        if (regex.Split(inputData).Length > 1)
            for (int i = 1; i < regex.Split(inputData).Length; i++ )
            {
                r = new Run(regex.Match(inputData).Value.Substring(0,1));
                r.Typography.Variants = FontVariants.Normal;
                p.Inlines.Add(r);

                r = new Run(regex.Match(inputData).Value.Substring(1, 1));
                r.Typography.Variants = FontVariants.Superscript;
                p.Inlines.Add(r);

                r = new Run(regex.Split(inputData)[i].Trim()); //r/n
                r.Typography.Variants = FontVariants.Normal;
                p.Inlines.Add(r);
            }
        focusFunction.Selection.Select(p.ContentEnd, p.ContentEnd);
    }
}


这篇关于RichTextbox数学函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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