Comments
- 6 minutes to read
The following topic describes how RichEditControl supports using comments in the document.
-
Insert, modify and delete the comments using the corresponding API.
Operate Comments in the User Interface
Provide end-users with a capability to manage comments in the UI.
Manage Comments Manually
Create a Comment
To create a comment to the document range, use the following API.
Member | Description |
---|---|
Paragraph.Range | Retrieves a range the given paragraph occupies. |
SubDocument.FindAll | Finds all document ranges that contain the given expression or text string. |
SubDocument.Comments | Provides access to the document’s collection of Comment instances. |
CommentCollection.Create | Creates a new item in the CommentCollection. |
The code snippet belows creates an empty comment associated with the specific phrase within the document.
Note
A complete sample project is available at https://github.com/DevExpress-Examples/comments-simple-example-t474988
//The target range is the specific phrase in the introduction's first paragraph
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)
{
//Create a new comment
Comment comment = richEditControl.Document.Comments.Create(foundRanges[0], "Johnson Alphonso D", new DateTime(2014, 4, 25));
}
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.
Note
A complete sample project is available at https://github.com/DevExpress-Examples/comments-simple-example-t474988
Document document = richEditControl.Document;
if (document.Comments.Count > 0)
{
//Create a new comment nested to the second comment in the collection
Comment nestedComment = document.Comments.Create("Brian Zetc", DateTime.Now, document.Comments[1]);
//Add text to the newly created comment
SubDocument nestedCommentDocument = nestedComment.BeginUpdate();
DocumentRange textRange = nestedCommentDocument.InsertText(nestedCommentDocument.CreatePosition(0),
"Suffix trees are comprehensively reviewed in Wikipedia");
nestedComment.EndUpdate(nestedCommentDocument);
}
Edit the Comment
Edit the Comment Content
To accomplish this task, use the API from the table below.
Member | Description |
---|---|
Comment.BeginUpdate | Opens the given comment for modification. |
SubDocument.InsertText | Inserts a text string to the specified position. |
TableCollection.Create | Inserts a table to the specified position within the document. |
ShapeCollection.InsertPicture | Inserts a floating picture to a given document position. |
DocumentImageCollection.Insert | Inserts an inline image to the specified position. |
ShapeCollection.InsertTextBox | Inserts a text box to the given position. |
Comment.EndUpdate | Finalizes the comment update. |
The following code sample adds text to the empty comment created earlier.
Note
A complete sample project is available at https://github.com/DevExpress-Examples/comments-simple-example-t474988
Document document = richEditControl.Document;
int commentCount = document.Comments.Count;
if (commentCount > 0)
{
//The target comment is the first one
Comment comment = document.Comments[0];
if (comment != null)
{
//Open the comment for modification
SubDocument commentDocument = comment.BeginUpdate();
//Add text to the comment range
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.");
//End the comment update
comment.EndUpdate(commentDocument);
}
}
Edit the Comment Attributes
To change the comment parameters (author, date, etc.), use the following members.
Member | Description |
---|---|
Comment.BeginUpdate | Enables the comment modification. |
Comment.Author | Specifies the comment’s author. |
Comment.Date | Specifies the comment’s last modified date. |
Comment.Name | Specifies the comment name. |
Comment.EndUpdate | Finalizes the comment update. |
The code snippet below changes the comment’s name, date and the author.
Note
A complete sample project is available at https://github.com/DevExpress-Examples/comments-simple-example-t474988
Document document = richEditControl.Document;
int commentCount = document.Comments.Count;
if (commentCount > 0)
{
document.BeginUpdate();
//The target is the second last comment
Comment comment = document.Comments[document.Comments.Count - 1];
//Change the comment's name, author and creation date
comment.Name = "Reference";
comment.Date = DateTime.Now;
comment.Author = "Vicars Annie";
document.EndUpdate();
}
Delete the Comment
To remove a specific comment from the document, use the CommentCollection.Remove method as shown in the code snippet below.
Document document = richEditControl.Document;
if (document.Comments.Count > 0)
{
//Remove the fourth document comment
document.Comments.Remove(document.Comments[3]);
}
Operate Comments in the User Interface
Display 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.
Note
The CommentOptions.Visibility property set to Hidden changes its value to Visible after adding a new comment.
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 How to: Create the RichEditControl with a Ribbon UI 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 the designer mode, click the RichEditControl’s smart tag and select Create Reviewing Pane.
Tip
Adding new comments to the document can be forbidden. To do that, set the RichEditControl’s DocumentCapabilitiesOptions.Comments property to Disabled.