We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on : November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How do I customize the way unsaved contents are saved in EditControl on closing a file or stream in it ?

 

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.

Article ID: Published Date: Last Revised Date: Platform: Control:
355 04/30/2011 07/10/2014 WinForms EditControl
Tags:
Did you find this information helpful?
Add Comment
You must log in to leave a comment

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon