Create the Comment
To create a comment to the document range, use the following API.
The code snippet belows creates an empty comment associated with the specific phrase within the document.
C#:Form1.cs |
DocumentRange[] foundRanges = richEditControl.Document.FindAll("an extensive problem in hardware and architecture is the construction of the emulation of checksums", SearchOptions.None);
if (foundRanges.Length > 0)
{
Comment comment = richEditControl.Document.Comments.Create(foundRanges[0], "Johnson Alphonso D", new DateTime(2014, 4, 25));
}
|
VB:Form1.vb |
Dim foundRanges() As DocumentRange = richEditControl.Document.FindAll("an extensive problem in hardware and architecture is the construction of the emulation of checksums", SearchOptions.None)
If foundRanges.Length > 0 Then
Dim comment As Comment = richEditControl.Document.Comments.Create(foundRanges(0), "Johnson Alphonso D", New Date(2014, 4, 25))
End If
|
Create a Nested Comment
The code snippet below demonstrates how to create a nested comment. To do that, use the CommentCollection.Create method with the passed parent comment.
C#:Form1.cs |
Document document = richEditControl.Document;
if (document.Comments.Count > 0)
{
Comment nestedComment = document.Comments.Create("Brian Zetc", DateTime.Now, document.Comments[1]);
SubDocument nestedCommentDocument = nestedComment.BeginUpdate();
DocumentRange textRange = nestedCommentDocument.InsertText(nestedCommentDocument.CreatePosition(0),
"Suffix trees are comprehensively reviewed in Wikipedia");
nestedComment.EndUpdate(nestedCommentDocument);
}
|
VB:Form1.vb |
Dim document As Document = richEditControl.Document
If document.Comments.Count > 0 Then
Dim nestedComment As Comment = document.Comments.Create("Brian Zetc", Date.Now, document.Comments(1))
Dim nestedCommentDocument As SubDocument = nestedComment.BeginUpdate()
Dim textRange As DocumentRange = nestedCommentDocument.InsertText(nestedCommentDocument.CreatePosition(0), "Suffix trees are comprehensively reviewed in Wikipedia")
nestedComment.EndUpdate(nestedCommentDocument)
End If
|
Edit the Comment
Edit the Comment Content
To accomplish this task, use the API from the table below.
The following code sample adds text to the empty comment created earlier.
C#:Form1.cs |
Document document = richEditControl.Document;
int commentCount = document.Comments.Count;
if (commentCount > 0)
{
Comment comment = document.Comments[0];
if (comment != null)
{
SubDocument commentDocument = comment.BeginUpdate();
commentDocument.InsertText(commentDocument.CreatePosition(0),
"J. Taylor, Enabling Voice - over - IP and RAID with sofa, in Proceedings of NOSSDAV, Oct. 1994.\r\n" +
@"R.Tarjan, S.Shenker, J.Gray, A.Einstein, Q.Thomas, and X.Sato, ""Deconstructing operating systems with flanchedripper"", in Proceedings of INFOCOM, Mar. 2000.");
comment.EndUpdate(commentDocument);
}
}
|
VB:Form1.vb |
Dim document As Document = richEditControl.Document
Dim commentCount As Integer = document.Comments.Count
If commentCount > 0 Then
Dim comment As Comment = document.Comments(0)
If comment IsNot Nothing Then
Dim commentDocument As SubDocument = comment.BeginUpdate()
commentDocument.InsertText(commentDocument.CreatePosition(0), "J. Taylor, Enabling Voice - over - IP and RAID with sofa, in Proceedings of NOSSDAV, Oct. 1994." & ControlChars.CrLf & "R.Tarjan, S.Shenker, J.Gray, A.Einstein, Q.Thomas, and X.Sato, ""Deconstructing operating systems with flanchedripper"", in Proceedings of INFOCOM, Mar. 2000.")
comment.EndUpdate(commentDocument)
End If
End If
|
Edit the Comment Attributes
To change the comment parameters (author, date, etc.), use the following members.
The code snippet below changes the comment's name, date and the author of the following comment.
C#:Form1.cs |
Document document = richEditControl.Document;
int commentCount = document.Comments.Count;
if (commentCount > 0)
{
document.BeginUpdate();
Comment comment = document.Comments[document.Comments.Count - 1];
comment.Name = "Reference";
comment.Date = DateTime.Now;
comment.Author = "Vicars Annie";
document.EndUpdate();
}
|
VB:Form1.vb |
Dim document As Document = richEditControl.Document
Dim commentCount As Integer = document.Comments.Count
If commentCount > 0 Then
document.BeginUpdate()
Dim comment As Comment = document.Comments(document.Comments.Count - 1)
comment.Name = "Reference"
comment.Date = Date.Now
comment.Author = "Vicars Annie"
document.EndUpdate()
End If
|
The image below demonstrates the result of the code execution.
Delete the Comment
To remove a specific comment from the document, use the CommentCollection.Remove method as shown in the code snippet below.
C# |
Document document = richEditControl.Document;
if (document.Comments.Count > 0)
{
document.Comments.Remove(document.Comments[3]);
}
|
VB |
Dim document As Document = richEditControl.Document
If document.Comments.Count > 0 Then
document.Comments.Remove(document.Comments(3))
End If
|
Comment Displaying Options
The comments are displayed in the Reviewing Pane or in balloons that appear in the document margins. The corresponding ranges are highlighted by a distinct color for each reviewer.
To change the comment displaying options, such as range highlighting color or comment visibility, use the CommentOptions's class properties.
Comments Functionality in the Command UI
End-users can insert, modify or remove the desired comment using the Review Ribbon tab. To learn how to provide the application with the ribbon menu, refer to the Lesson 5 - Create Separate Ribbon Pages for a Rich Text Editor topic.
The Comment group on the Review tab allows end-users to insert new comments, remove existing one(s) and navigate through all the comments in the document.
The Tracking group buttons allow end-users to highlight comments in the document, to filter them by the author, to specify whether to display the comments in the document margins or show the Reviewing Pane.
To provide the application with the Reviewing Pane, in XAML, set the RichEditControl.ShowReviewingPane property to true.
Xaml |
<dxre:RichEditControl ShowReviewingPane="True"/>
|