Spread Windows Forms 16
Spread Windows Forms 16.0 Product Documentation / Developer's Guide / Cells / Adding a Comment to a Cell
In This Topic
    Adding a Comment to a Cell
    In This Topic

    Spread for WinForms supports adding comments to cells in a worksheet. You can add a plain text comment or note by referring to Adding a Note to a Cell topic.

    Additionally, you can enable the EnhancedShapeEngine property to add a string or RichText instances by using the IRange.AddComment method.

    You can modify the added comment by using the IRange.Comment property. For example, the image below shows a default comment as well as a customized comment. The customized comment is set to always be visible and has shape properties such as background color, shape border style, and border color.

    The following code shows how to set comments.

    Copy Code
    // Get activesheet
    GrapeCity.Spreadsheet.IWorksheet TestActiveSheet = fpSpread1.AsWorkbook().ActiveSheet;
    // Enable enhanced shape engine
    fpSpread1.Features.EnhancedShapeEngine = true;
    string username = "Admin" + ":";
    // Initilize richtext object
    GrapeCity.Spreadsheet.RichText richText = new GrapeCity.Spreadsheet.RichText(username + "\r\nThis is a rich text \r\nsupported comment");
    // Setting style
    GrapeCity.Spreadsheet.Font font = GrapeCity.Spreadsheet.Font.Empty;
    font.Bold = true;
    GrapeCity.Spreadsheet.Font font2 = GrapeCity.Spreadsheet.Font.Empty;
    font2.Italic = true;
    font2.Underline = GrapeCity.Spreadsheet.UnderlineStyle.Double;
    // Adding style to rich text
    richText.Format(0, username.Length, font);
    richText.Format(17, 9, font2);
    // Adding a comment to cell
    GrapeCity.Spreadsheet.IComment comment = TestActiveSheet.Cells["B2"].AddComment(richText);
    // Customizing comment style
    TestActiveSheet.Cells["B2"].Comment.Visible = true; // Always show comment
    TestActiveSheet.Cells["B2"].Comment.Shape.Fill.BackColor.ARGB = Color.Orange.ToArgb();  // Change comment background color
    TestActiveSheet.Cells["B2"].Comment.Shape.Line.Style = GrapeCity.Drawing.LineStyle.ThickThin;   // Change border style
    TestActiveSheet.Cells["B2"].Comment.Shape.Line.Weight = 5;  // Change border thickness
    TestActiveSheet.Cells["B2"].Comment.Shape.Line.ForeColor.ARGB = Color.DeepSkyBlue.ToArgb(); // Change border color
    Copy Code
    'Get activesheet
    Dim TestActiveSheet As GrapeCity.Spreadsheet.IWorksheet = FpSpread1.AsWorkbook().ActiveSheet
    'Enable enhanced shape engine
    FpSpread1.Features.EnhancedShapeEngine = True
    Dim username As String = "Admin" & ":"
    'Initilize richtext object
    Dim richText As GrapeCity.Spreadsheet.RichText = New GrapeCity.Spreadsheet.RichText(username & vbCrLf & "This is a rich text " & vbCrLf & "supported comment")
    'Setting style
    Dim font As GrapeCity.Spreadsheet.Font = GrapeCity.Spreadsheet.Font.Empty
    font.Bold = True
    Dim font2 As GrapeCity.Spreadsheet.Font = GrapeCity.Spreadsheet.Font.Empty
    font2.Italic = True
    font2.Underline = GrapeCity.Spreadsheet.UnderlineStyle.Double
    'Adding style to rich text
    richText.Format(0, username.Length, font)
    richText.Format(17, 9, font2)
    'Adding a comment to cell
    Dim comment As GrapeCity.Spreadsheet.IComment = TestActiveSheet.Cells("B2").AddComment(richText)
    'Customizing comment style
    TestActiveSheet.Cells("B2").Comment.Visible = True  'Always show comment
    TestActiveSheet.Cells("B2").Comment.Shape.Fill.BackColor.ARGB = Color.Orange.ToArgb()   'Change comment background color
    TestActiveSheet.Cells("B2").Comment.Shape.Line.Style = GrapeCity.Drawing.LineStyle.ThickThin    'Change border style
    TestActiveSheet.Cells("B2").Comment.Shape.Line.Weight = 5   'Change border thickness
    TestActiveSheet.Cells("B2").Comment.Shape.Line.ForeColor.ARGB = Color.DeepSkyBlue.ToArgb()  'Change border color

    Threaded Comments

    Users can view threaded comments in the Spread UI. This helps in connecting several comments together and presenting a virtual conversation in the workbook.

    Using Code

    You can add threaded comments by using the IRange.AddCommentThreaded method.

    Copy Code
    // Threaded comments
    fpSpread1.LegacyBehaviors = LegacyBehaviors.None;
    fpSpread1.Features.EnhancedShapeEngine = true;
    fpSpread1.AsWorkbook().TestActiveSheet.Cells["C5"].AddCommentThreaded("Threaded comment supported").AddReply("First reply");
    Copy Code
    ' Threaded comments
     fpSpread1.LegacyBehaviors = LegacyBehaviors.None
     fpSpread1.Features.EnhancedShapeEngine = True
     fpSpread1.AsWorkbook().TestActiveSheet.Cells("C5").AddCommentThreaded("Threaded comment supported").AddReply("First reply")

    Gradient Fill Effects

    You can add gradient effects to emphasize the comments by applying fill-color and patterns.


    Using Code

    To add the gradient effects, use the Fill property of the IShapeBase interface, which gets an object of the IFillFormat interface for a specified shape that contains the fill formatting properties for shape.

    Copy Code
    fpSpread1.Features.EnhancedShapeEngine = true;
    IShape shape;
    shape = TestActiveSheet.Cells["A1"].AddComment("InsetPen = false").Shape;
    TestActiveSheet.Cells["A1"].Comment.Visible = true;
    shape.Fill.OneColorGradient(GrapeCity.Spreadsheet.Drawing.GradientStyle.FromCenter, 1, 1);
    shape.Fill.GradientStops.Insert(0xffff00, 0);
    shape.Fill.GradientStops.Insert(0xffffff, 0.5);
    shape.Fill.GradientStops.Insert(0x00ffff, 1);
    shape.Fill.GradientStops[0].Color.SchemeColor = 23;
    shape.Fill.PathShadeType = GrapeCity.Drawing.PathShadeType.Shape;
    IShape aa = fpSpread1.AsWorkbook().ActiveSheet.Cells["A1"].Comment.Shape;
    Copy Code
    fpSpread1.Features.EnhancedShapeEngine = True
    Dim shape As IShape
    shape = TestActiveSheet.Cells("A1").AddComment("InsetPen = false").Shape
    TestActiveSheet.Cells("A1").Comment.Visible = True
    shape.Fill.OneColorGradient(GrapeCity.Spreadsheet.Drawing.GradientStyle.FromCenter, 1, 1)
    shape.Fill.GradientStops.Insert(0xffff00, 0)
    shape.Fill.GradientStops.Insert(0xffffff, 0.5)
    shape.Fill.GradientStops.Insert(0x00ffff, 1)
    shape.Fill.GradientStops(0).Color.SchemeColor = 23
    shape.Fill.PathShadeType = GrapeCity.Drawing.PathShadeType.Shape
    Dim aa As IShape =  fpSpread1.AsWorkbook().ActiveSheet.Cells("A1").Comment.Shape

    Using Runtime UI

    You can add or manipulate gradient fill effects at run time via the Fill Effects dialog. The Fill Effects dialog provides options like colors, variants, shading styles, patterns, and a sample preview to view the gradient effect.

    To invoke the dialog at runtime, select the comment on the sheet and use the keyboard shortcut keys combination Ctrl+1, or select the Format Comment option from the built-in context menu.

    In the Format Comments dialog, navigate to the Colors and Lines tab and select the Fill Effects option from the Color picker dropdown to view the Fill Effects dialog.

    For the keyboard shortcut to work, set the ExcelCompatibleKeyboardShortcuts property to true.

    You can also invoke the Fill Effects dialog at runtime using the FillEffects method of the BuiltInDialogs class. To learn more about this class, see Working with BuiltIn Dialogs.

    Using Spread Designer

    To view comments and add gradient effects to the block in the Spread Designer, follow the below mentioned steps:

    1. Set the EnhancedShapeEngine and ExcelCompatibleKeyboardShortcuts to true in the properties window. 
    2. Select the comment on which you want to add or modify the gradient effect. 
    3. Invoke the Format Comment dialog.
    4. Click the Fill Effects button from the Colors and Lines tab to open the Fill Effects dialog.