How to customize the way unsaved contents are saved in WinForms SyntaxEditor (EditControl) on closing a file or stream in it?
Customize the unsaved content
The EditControl's SaveOnClose property can be used for this purpose. The SaveOnClose property allows the user to cancel (or show) the default save prompt dialog that appears when the form hosting EditControl containing unsaved contents is closed.
C#
this.editControl1.SaveOnClose = false;
VB
Me.editControl1.SaveOnClose = False
When the SaveOnClose property is set to false, the default save prompt dialog does not appear. The user should perform some custom save routine as shown below in the host form's Closing event handler to save the unsaved contents in the EditControl, if not they will be lost.
C#
private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e) { if (this.editControl1.SaveOnClose == false) { if (this.editControl1.SaveModified() == true) // Perform custom save routine or show custom save dialog or set Cancel to false e.Cancel = false; else e.Cancel = true; } }
VB
Private Sub Form1_Closing(sender As Object, e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing If Me.editControl1.SaveOnClose = False Then If Me.editControl1.SaveModified() = True Then ' Perform custom save routine or show custom save dialog or set Cancel to false e.Cancel = False Else e.Cancel = True End If End If End Sub 'Form1_Closing
When the SaveOnClose property is set to true, the default save prompt dialog appears on closing EditControl containing unsaved contents in it. This task can be further customized by handling the EditControl's Closing event. The Closing event is triggered just before a file or stream is being closed in the EditControl.
C#
private void editControl1_Closing(object sender, Syncfusion.Windows.Forms.Edit.StreamCloseEventArgs e) { // Cancel the file or stream closing action e.Action = SaveChangesAction.Cancel; // Close the file or stream without saving the unsaved contents, the changes will be lost forever e.Action = SaveChangesAction.Discard; // Silently saves the unsaved contents to the currently open file or stream // If the contents have not been saved to a file or stream yet, the Save dialog is displayed e.Action = SaveChangesAction.Save; // Displays the default Save prompt dialog if there are unsaved contents when the file or stream is closed e.Action = SaveChangesAction.ShowDialog; }
VB
Private Sub editControl1_Closing(sender As Object, e As Syncfusion.Windows.Forms.Edit.StreamCloseEventArgs) Handles editControl1.StreamClose ' Cancel the file or stream closing action e.Action = SaveChangesAction.Cancel ' Close the file or stream without saving the unsaved contents, the changes will be lost forever e.Action = SaveChangesAction.Discard ' Silently saves the unsaved contents to the currently open file or stream ' If the contents have not been saved to a file or stream yet, the Save dialog is displayed e.Action = SaveChangesAction.Save ' Displays the default Save prompt dialog if there are unsaved contents when the file or stream is closed e.Action = SaveChangesAction.ShowDialog End Sub 'editControl1_Closing
The default value of e.Action is SaveChangesAction.ShowDialog.
Reference link: https://help.syncfusion.com/windowsforms/syntax-editor/file-operation#save-as-stream