Back to Devexpress

RichEditControl.CreateNewDocument(Boolean) Method

windowsforms-devexpress-dot-xtrarichedit-dot-richeditcontrol-dot-createnewdocument-x28-system-dot-boolean-x29.md

latest8.1 KB
Original Source

RichEditControl.CreateNewDocument(Boolean) Method

Creates and loads a new empty document. Optionally, raises the DocumentClosing event.

Namespace : DevExpress.XtraRichEdit

Assembly : DevExpress.XtraRichEdit.v25.2.dll

NuGet Package : DevExpress.Win.RichEdit

Declaration

csharp
public virtual bool CreateNewDocument(
    bool raiseDocumentClosing = false
)
vb
Public Overridable Function CreateNewDocument(
    raiseDocumentClosing As Boolean = False
) As Boolean

Optional Parameters

NameTypeDefaultDescription
raiseDocumentClosingBooleanFalse

true , to raise the RichEditControl.DocumentClosing event; otherwise, false.

|

Returns

TypeDescription
Boolean

true if a new document is created and loaded; otherwise, false.

|

Remarks

The CreateNewDocument helps prevent users from losing unsaved changes when a new document is created.

If the raiseDocumentClosing parameter is set to true and the RichEditControl’s document has unsaved changes (the RichEditControl.Modified property is true ), the RichEditControl.DocumentClosing event is fired.

By handling the DocumentClosing event, you can set e.Cancel to true to cancel unloading a document. A new document will not be created and the CreateNewDocument method returns false.

If the new document was created and successfully loaded, the CreateNewDocument method returns true.

Example

The following code creates a new empty document with default formatting.

The RichEditControl instance is passed to the BarItem.ItemClick event handler using the BarItem.Tag property.

View Example

csharp
static void buttonCustomAction_ItemClick_NewDocument(object sender, ItemClickEventArgs e) {
    RichEditControl richEdit = e.Item.Tag as RichEditControl;
    richEdit.CreateNewDocument();
}
vb
Private Shared Sub buttonCustomAction_ItemClick_NewDocument(ByVal sender As Object, ByVal e As ItemClickEventArgs)
    Dim richEdit As RichEditControl = TryCast(e.Item.Tag, RichEditControl)
    richEdit.CreateNewDocument()
End Sub

The following code snippets (auto-collected from DevExpress Examples) contain references to the CreateNewDocument(Boolean) method.

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.

winforms-richeditcontrol-common-api/CS/RichEditAPISample/Form1.cs#L401

csharp
codeEditor.BeforeCompile();
richEditControl.CreateNewDocument();
document.Unit = DevExpress.Office.DocumentUnit.Document;

winforms-richedit-text-autocorrect-feature/CS/Expander/Form1.cs#L18

csharp
InitializeComponent();
richEditControl1.CreateNewDocument();
SetAutoCorrectOptions();

winforms-richedit-use-calculatedocumentvariable-event-to-insert-formatted-content/CS/Form1.cs#L40

csharp
richEditControl1.CreateNewDocument();
richEditControl1.Document.AppendDocumentContent(server.Document.Range);

winforms-richedit-replace-standard-command-with-custom-command/CS/CustomCommand/Form1.cs#L21

csharp
MyFactoryHelper.SetMyNewCommandFactory(this.richEditControl1);
richEditControl1.CreateNewDocument();
richEditControl1.Document.AppendSingleLineText("Type at least 7 paragraphs to be able to save the document.");

winforms-rich-text-editor-retain-original-image-uri-in-html-document/CS/Form1.cs#L17

csharp
richEditControl1.DocumentLoaded += richEditControl1_DocumentLoaded;
richEditControl1.CreateNewDocument();
DocumentPosition pos = richEditControl1.Document.CaretPosition;

winforms-richeditcontrol-common-api/VB/RichEditAPISample/Form1.vb#L391

vb
codeEditor.BeforeCompile()
richEditControl.CreateNewDocument()
document.Unit = DevExpress.Office.DocumentUnit.Document

winforms-richedit-text-autocorrect-feature/VB/Expander/Form1.vb#L17

vb
InitializeComponent()
richEditControl1.CreateNewDocument()
SetAutoCorrectOptions()

winforms-richedit-use-calculatedocumentvariable-event-to-insert-formatted-content/VB/Form1.vb#L31

vb
richEditControl1.Document.MailMerge(myMergeOptions, server.Document)
richEditControl1.CreateNewDocument()
richEditControl1.Document.AppendDocumentContent(server.Document.Range)

winforms-richedit-replace-standard-command-with-custom-command/VB/CustomCommand/Form1.vb#L21

vb
MyFactoryHelper.SetMyNewCommandFactory(Me.richEditControl1)
richEditControl1.CreateNewDocument()
richEditControl1.Document.AppendSingleLineText("Type at least 7 paragraphs to be able to save the document.")

winforms-rich-text-editor-retain-original-image-uri-in-html-document/VB/Form1.vb#L13

vb
AddHandler richEditControl1.DocumentLoaded, AddressOf richEditControl1_DocumentLoaded
richEditControl1.CreateNewDocument()
Dim pos As DocumentPosition = richEditControl1.Document.CaretPosition

See Also

RichEditControl Class

RichEditControl Members

DevExpress.XtraRichEdit Namespace