采用强大的扩展方法来处理跟踪的变更

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

                                         点击下载最新版TX Text Control .NET for Windows Forms   


在TX Text Control中,可以通过用户文档中的跟踪更改来启用文档协作。 这种方式表示任何人修改文件都会对文档做出改变。拒绝和接受跟踪的变更都需要使用TXTextControl.TrackedChangeCollection.Remove方法从TXTextControl.TrackedChangeCollection中删除特定更改。有时,需要通过给定的用户名从整个文档中删除所有更改。实现这种效果有两种扩展方法。扩展方法使您可以向现有类添加其他功能。  

以下扩展方法从TrackedChangeCollection中删除所有更改或从所有TextPart中删除所有更改:


namespace TrackedChangeCollectionExtensions
{
    public static class TrackedChangeCollectionExtensions
    {
        // removes all changes in the TrackedChangeCollection with a given username
        public static int RemoveAll(
            this TXTextControl.TrackedChangeCollection trackdChangeCollection, 
            string username, bool accept)
        {
            List<TrackedChange> myTrackedChanges = new List<TrackedChange>();

            // loop through all changes
            foreach (TXTextControl.TrackedChange trackedChange in trackdChangeCollection)
            {
                if (trackedChange.UserName == username)
                    myTrackedChanges.Add(trackedChange);
            }

            // delete all changes
            foreach (TrackedChange listedTrackedChange in myTrackedChanges)
                trackdChangeCollection.Remove(listedTrackedChange, true);

            return myTrackedChanges.Count;
        }

        // removes all changes in all TextParts with a given username
        public static int RemoveAllTrackedChanges(
            this TXTextControl.TextPartCollection textPartCollection, 
            string username, bool accept)
        {
            // counter
            var deletedTrackedChanges = 0;

            // loop through all text parts
            foreach (IFormattedText textPart in textPartCollection)
            {
                List<TrackedChange> myTrackedChanges = new List<TrackedChange>();

                // loop through all changes
                foreach (TXTextControl.TrackedChange trackedChange in textPart.TrackedChanges)
                {
                    if (trackedChange.UserName == username)
                        myTrackedChanges.Add(trackedChange);
                }

                // delete all changes
                foreach (TrackedChange listedTrackedChange in myTrackedChanges)
                {
                    textPart.TrackedChanges.Remove(listedTrackedChange, true);
                    deletedTrackedChanges++;
                }
            }

            return deletedTrackedChanges;
        }
    }
}

例如:为了接受用户development@devteam.com所做的所有更改,只需要以下呼叫:

var removedChanges = textControl1.TrackedChanges.RemoveAll("development@devteam.com", true);

如果您需要拒绝所有文本部分中的所有更改,包括页眉,页脚,主文本和文本框架,可以使用以下调用:

var  removedChanges  =  textControl1。TextParts。RemoveAllTrackedChanges(“ development@devteam.com ”,false);

这种方式是从TX Text Control .NET for Windows Forms X16  版本开始的,需要下载相关的软件才可以完成。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值