找回密码
 立即注册

QQ登录

只需一步,快速开始

iceman

社区贡献组

270

主题

1万

帖子

1万

积分

社区贡献组

积分
19311

活字格认证微信认证勋章元老葡萄

iceman
社区贡献组   /  发表于:2012-5-9 16:30  /   查看:6569  /  回复:2
TX Text Control 是一款功能丰富的文字处理控件,它以可重复使用控件的形式为开发人员提供了Word中常用的文字处理功能,对于需要强大且灵活的文档处理能力的应用程序而言,是理想的选择。

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

1.通过 textControl1_KeyDown 事件捕捉 Delete 键:
  1. private void textControl1_KeyDown(object sender, KeyEventArgs e)
  2.         {
  3.             //Delete
  4.             if (e.KeyValue == 46 )
  5.             {
  6.                 e.Handled = true;

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

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

  12.                 this.textControl1.Selection.Start = start;
  13.                 this.textControl1.Selection.Length = length;
  14.                 this.textControl1.Selection.Strikeout = true;
  15.                 this.textControl1.Selection.ForeColor = Color.Red;


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

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

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

  23.                 if (currentColumn == this.textControl1.Lines[currentLine].Length || currentColumn == this.textControl1.Lines[currentLine].Length - 1)
  24.                 {
  25.                     if (currentLine == this.textControl1.Lines.Count)
  26.                     {
  27.                         this.textControl1.InputPosition = new TXTextControl.InputPosition(currentPage, currentLine, currentColumn);
  28.                     }
  29.                     else
  30.                     {
  31.                         this.textControl1.InputPosition = new TXTextControl.InputPosition(currentPage, currentLine + 1, 0);
  32.                     }
  33.                 }
  34.                 else
  35.                 {
  36.                     this.textControl1.InputPosition = new TXTextControl.InputPosition(currentPage, currentLine, currentColumn + 1);
  37.                 }
  38.             }
  39.         }
复制代码
2.通过 textControl1_KeyPress 事件捕捉 Backspace 键:
  1. private void textControl1_KeyPress(object sender, KeyPressEventArgs e)
  2.         {
  3.             //Backspace
  4.             if (e.KeyChar.ToString() == "\b")
  5.             {
  6.                 e.Handled = true;

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

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

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

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

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

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

  23.                 if (currentColumn == 0)
  24.                 {
  25.                     if (currentLine == 1)
  26.                     {
  27.                         this.textControl1.InputPosition = new TXTextControl.InputPosition(currentPage, currentLine, currentColumn);
  28.                     }
  29.                     else
  30.                     {
  31.                         this.textControl1.InputPosition = new TXTextControl.InputPosition(currentPage, currentLine - 1, this.textControl1.Lines[currentLine - 1].Length - 1);
  32.                     }
  33.                 }
  34.                 else
  35.                 {
  36.                     this.textControl1.InputPosition = new TXTextControl.InputPosition(currentPage, currentLine, currentColumn - 1);
  37.                 }
  38.             }
  39.         }
复制代码
Demo 下载:
测试环境:TX Control .NET 17.0 && VS 2010
TXTrackChanges.zip (44.34 KB, 下载次数: 757)

2 个回复

倒序浏览
ZenosZeng讲师达人认证 悬赏达人认证
超级版主   /  发表于:2012-5-9 17:38:00
沙发
帅,太需要该功能的实现方法了
回复 使用道具 举报
iceman
社区贡献组   /  发表于:2012-5-9 17:47:00
板凳

回复 2# dof 的帖子

回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部