RichEditControl控件的ContentChanged事件执行两次的解决办法

将近没事,在学习Devexpress.用到了RichEditControl控件,当在加载一个件时,发现ContentChanged事件被触发了两次。

想了半个小时也没想原来来。于是去官网下载官方文档查看,恍然大悟。原谅如下:

Note that methods such as DevExpress.XtraRichEdit.API.Native.SubDocument.InsertText and DevExpress.XtraRichEdit.API.Native.SubDocument.InsertDocumentContent result in significant changes of the internal document model. The ContentChanged event occurs two times in this case, and you cannot predict when the second ContentChanged event fires.

To distinguish between loading a new document and a situation when the document is modified, use the Modified property within the event handler. When a document is newly created using the CreateNewDocument method, loaded from a file or from a stream, or created by assigning a value to a certain text property, the Modified value is false. Otherwise, it is set to true.

 

意思就是说:在用到InsertText和InsertDocumentContent等方法时会导致文档内部结构发生变化。在这种情况下,ContentChanged事件会被触发两次,并且不能预测

第二次在什么时候引发。

为了区分是加载一个新文档还是文档被改变,在事件处理中可以使用Modified属性。当一个文档通过CreateNewDocument 方法 、从文件或者流中加载、或者

通过指定某些值给一些text属性创建时,Modified属性值为false,其他情况下均为true.

 

也就是说在事件处理中,可以加入以下代码:

    if (this.richEditControl1.Modified)  //非新创建文件,内容发生更改时
            {
                //doSomething
            }

    else  //新创建的文件

    {

      //doSomething

    }

 

转载于:https://www.cnblogs.com/xiaozhi123/p/4074261.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值