Back to Devexpress

RichEditControl.Modified Property

windowsforms-devexpress-dot-xtrarichedit-dot-richeditcontrol-c1a5b4f6.md

latest6.4 KB
Original Source

RichEditControl.Modified Property

Gets or sets whether the control’s content was modified since it was last saved.

Namespace : DevExpress.XtraRichEdit

Assembly : DevExpress.XtraRichEdit.v25.2.dll

NuGet Package : DevExpress.Win.RichEdit

Declaration

csharp
[Browsable(false)]
[DefaultValue(false)]
public bool Modified { get; set; }
vb
<Browsable(False)>
<DefaultValue(False)>
Public Property Modified As Boolean

Property Value

TypeDefaultDescription
Booleanfalse

true if the control’s content was modified since it was last saved; otherwise, false.

|

Remarks

The following actions change the Modified property value:

RichEditControl and SnapControl

  • Add, delete, cut or paste content;
  • Change text format (font, paragraph properties, apply style, change direction);
  • Change document layout (insert section break, divide into columns, change margins, orientation);
  • Edit character, paragraph and table styles;
  • Insert or modify document elements (drawing objects, tables, comments, etc.);

The RichEditControl.SaveDocument, RichEditControl.SaveDocumentAs or Document.SaveDocument method call does not automatically change the Modified property value. However, the SaveDocumentCommand or SaveDocumentAsCommand execution changes the Modified property value to false.

When the Modified property value is changed, the RichEditControl.ModifiedChanged event raises.

The code sample below checks the Modified property in the RichEditControl.DocumentClosing event handler and shows the message box with the question whether to save changes before the application is closed.

csharp
void richEditControl_DocumentClosing(object sender, CancelEventArgs e)
{
    if (RichEdit.Modified)
    {
        string currentFileName = RichEdit.Options.DocumentSaveOptions.CurrentFileName;
        string message = !string.IsNullOrEmpty(currentFileName) ?
            string.Format("Do you want to save the changes you made for '{0}'?", currentFileName) : "Do you want to save the changes?";
        DialogResult result = XtraMessageBox.Show(message, "Warning", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning);
        if (result == DialogResult.Yes)
            RichEdit.SaveDocument();
        e.Cancel = result == DialogResult.Cancel;
    }
}
vb
Private Sub richEditControl_DocumentClosing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs)
    If RichEdit.Modified Then
        Dim currentFileName As String = RichEdit.Options.DocumentSaveOptions.CurrentFileName
        Dim message As String = If(Not String.IsNullOrEmpty(currentFileName), String.Format("Do you want to save the changes you made for '{0}'?", currentFileName), "Do you want to save the changes?")
        Dim result As DialogResult = XtraMessageBox.Show(message, "Warning", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning)
        If result = DialogResult.Yes Then RichEdit.SaveDocument()
        e.Cancel = result = DialogResult.Cancel
    End If
End Sub

The following code snippets (auto-collected from DevExpress Examples) contain references to the Modified property.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

how-to-use-richeditcontrol-in-bound-mode/CS/Form1.cs#L27

csharp
void Cars_ColumnChanged(object sender, DataColumnChangeEventArgs e) {
    if (!richEditControl1.Modified)
        e.Row.AcceptChanges();

winforms-richeditcontrol-common-api/CS/RichEditAPISample/CodeExamples/RichEditControlActions.cs#L592

csharp
base.ExecuteCore();
if(!(this.Control as RichEditControl).Modified) {
    MessageBox.Show("Document is saved successfully");

how-to-use-richeditcontrol-in-bound-mode/VB/Form1.vb#L25

vb
Private Sub Cars_ColumnChanged(ByVal sender As Object, ByVal e As DataColumnChangeEventArgs)
    If Not richEditControl1.Modified Then e.Row.AcceptChanges()
End Sub

winforms-richeditcontrol-common-api/VB/RichEditAPISample/CodeExamples/RichEditControlActions.vb#L606

vb
MyBase.ExecuteCore()
If (Not TryCast(Me.Control, RichEditControl).Modified) Then
    MessageBox.Show("Document is saved successfully")

See Also

ContentChanged

RichEditControl Class

RichEditControl Members

DevExpress.XtraRichEdit Namespace