TX Text Control 模仿 MSWord 修改记录功能

TX Text Control 是一款功能丰富的文字处理控件,它以可重复使用控件的形式为开发人员提供了Word中常用的文字处理功能,对于需要强大且灵活的文档处理能力的应用程序而言,是理想的选择。这篇文章就介绍怎样实现简单的 MSWord 修改记录功能。

发布于 2012/11/16 00:00

TX Text Control 是一款功能丰富的文字处理控件,它以可重复使用控件的形式为开发人员提供了Word中常用的文字处理功能,对于需要强大且灵活的文档处理能力的应用程序而言,是理想的选择。

这篇文章就介绍怎样实现简单的 MSWord 修改记录功能。

1.通过 textControl1_KeyDown 事件捕捉 Delete 键:

 
private void textControl1_KeyDown(object sender, KeyEventArgs e)
        {
            //Delete
            if (e.KeyValue == 46 )
            {
                e.Handled = true;

                int currentLine = this.textControl1.InputPosition.Line;
                int currentColumn = this.textControl1.InputPosition.Column;
                int currentPage = this.textControl1.InputPosition.Page;

                int start = this.textControl1.InputPosition.TextPosition;
                int length = 1;

                this.textControl1.Selection.Start = start;
                this.textControl1.Selection.Length = length;
                this.textControl1.Selection.Strikeout = true;
                this.textControl1.Selection.ForeColor = Color.Red;


                TXTextControl.TextField delTextField = new TXTextControl.TextField();
                delTextField.ID = delID;
                delID++;
                delTextField.Text = this.textControl1.Selection.Text;

                this.textControl1.Selection.Text = "";

                this.textControl1.TextFields.Add(delTextField);
                DelTextFieldCol.Add(delTextField);

                if (currentColumn == this.textControl1.Lines[currentLine].Length || currentColumn == this.textControl1.Lines[currentLine].Length - 1)
                {
                    if (currentLine == this.textControl1.Lines.Count)
                    {
                        this.textControl1.InputPosition = new TXTextControl.InputPosition(currentPage, currentLine, currentColumn);
                    }
                    else
                    {
                        this.textControl1.InputPosition = new TXTextControl.InputPosition(currentPage, currentLine + 1, 0);
                    }
                }
                else
                {
                    this.textControl1.InputPosition = new TXTextControl.InputPosition(currentPage, currentLine, currentColumn + 1);
                }
            }
        }
复制代码

2.通过 textControl1_KeyPress 事件捕捉 Backspace 键:

 
private void textControl1_KeyPress(object sender, KeyPressEventArgs e)
        {
            //Backspace
            if (e.KeyChar.ToString() == "\b")
            {
                e.Handled = true;

                int currentLine = this.textControl1.InputPosition.Line;
                int currentColumn = this.textControl1.InputPosition.Column;
                int currentPage = this.textControl1.InputPosition.Page;

                int start = this.textControl1.InputPosition.TextPosition;
                int length = 1;

                this.textControl1.Selection.Start = start - 1;
                this.textControl1.Selection.Length = length;
                this.textControl1.Selection.Strikeout = true;
                this.textControl1.Selection.ForeColor = Color.Red;

                TXTextControl.TextField delTextField = new TXTextControl.TextField();
                delTextField.ID = delID;
                delID++;
                delTextField.Text = this.textControl1.Selection.Text;

                //this.textControl1.Selection.Text = "";

                this.textControl1.TextFields.Add(delTextField);
                DelTextFieldCol.Add(delTextField);

                if (currentColumn == 0)
                {
                    if (currentLine == 1)
                    {
                        this.textControl1.InputPosition = new TXTextControl.InputPosition(currentPage, currentLine, currentColumn);
                    }
                    else
                    {
                        this.textControl1.InputPosition = new TXTextControl.InputPosition(currentPage, currentLine - 1, this.textControl1.Lines[currentLine - 1].Length - 1);
                    }
                }
                else
                {
                    this.textControl1.InputPosition = new TXTextControl.InputPosition(currentPage, currentLine, currentColumn - 1);
                }
            }
        }
复制代码

环境:TX Control .NET 17.0 && VS 2010

关于葡萄城

葡萄城是专业的软件开发技术和低代码平台提供商,以“赋能开发者”为使命,致力于通过表格控件、低代码和BI等各类软件开发工具和服务,一站式满足开发者需求,帮助企业提升开发效率并创新开发模式。葡萄城开发技术始于1980年,40余年来始终聚焦软件开发技术,有深厚的技术积累和丰富的产品线。是业界能够同时赋能软件开发和低代码开发的企业。凭借过硬的产品能力、活跃的用户社区和丰富的伙伴生态,与超过3000家合作伙伴紧密合作,产品广泛应用于信息和软件服务、制造、交通运输、建筑、金融、能源、教育、公共管理等支柱产业。

推荐相关案例
推荐相关资源
关注微信
葡萄城社区二维码

关注“葡萄城社区”

活字格低代码二维码

关注“活字格低代码”

想了解更多信息,请联系我们, 随时掌握技术资源和产品动态