It's almost okay. After learning about devexpress, we used the richeditcontrol Control. When loading an object, we found that the contentchanged event was triggered twice.
I thought about it for half an hour. So I went to the official website to download the official documentation and suddenly realized that. Forgive me for the following:
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.ContentchangedEvent occurs two times in this case, and you cannot predict when the secondContentchangedEvent 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,ModifiedValue isFalse. Otherwise, it is setTrue.
This means that when inserttext and insertdocumentcontent are used, the internal structure of the document changes. In this case,ContentchangedThe event is triggered twice and cannot be predicted.
When is the second trigger.
To distinguish whether a new document is loaded or the document is changed, you can use the modified attribute in event processing. When a document is loaded from a file or stream through the createnewdocument method, or
When you create text attributes by specifying some values, the value of the modified attribute is false. In other cases, the value is true.
In other words, you can add the following code to event processing:
If (this. richeditcontrol1.modified) // when the content of a non-new file is changed
{
// Dosomething
}
Else // newly created File
{
// Dosomething
}
Solution to the richeditcontrol contentchanged event twice