RichEditControl控件的ContentChanged事件执行两次的解决办法
2014-11-04 17:33
225 查看
将近没事,在学习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
}
想了半个小时也没想原来来。于是去官网下载官方文档查看,恍然大悟。原谅如下:
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
}
相关文章推荐
- (转载)js(jquery)的on绑定点击事件执行两次的解决办法
- android setOnKeyListener事件两次执行解决办法
- QT一个事件被重复执行两次的解决办法
- JQUERY $() $(document).ready() 事件执行两次解决办法。
- textview文本片段点击事件与textview点击事件冲突执行两次(最终解决办法)
- input内容改变后,ie11中change事件执行两次的解决办法
- textview文本片段点击事件与textview点击事件冲突执行两次(最终解决办法)
- VC2010 控件的事件窗口面板空白解决办法
- DXperience之RichEditControl控件Bug解决方法
- 手动调用控件的RenderControl方法,OnPreRender方法不执行的解决办法.
- Java Web开发中,自定义过滤器被执行两次的原因分析及解决办法
- SearchView中onQueryTextSubmit()执行两次的原因和解决办法
- C# Page_load()事件 执行两遍 出现的几种情况以及解决办法
- 网页中的数据提交后,在数据库执行两次的解决办法
- Android中ListView实现子控件点击事件后ListView点击事件失效解决办法
- 关于VS2003中控件丢事件的解决办法
- VC2010 控件的事件窗口面板空白解决办法
- C# Page_load()事件 执行两遍 出现的几种情况以及解决办法
- asp.net页面动态添加控件造成控件事件不响应的解决办法
- 刷新后 按钮事件再次执行的解决办法