Web forum is in read-only mode. Login as active registered customer for write access
  Forum Search   New Posts New Posts

Add image in acomment (note)

 Post Reply Post Reply
Author
Sandoz Jean-Luc View Drop Down
New Member
New Member
Avatar

Joined: 08 Apr 2014
Posts: 6
Post Options Post Options   Quote Sandoz Jean-Luc Quote  Post ReplyReply Direct Link To This Post Topic: Add image in acomment (note)
    Posted: 29 Mar 2019 at 8:42am
Hello,
How do I add an image to a comment?

I want to show an image when the user hover the cell, something like this:
Image in comment
Thank you in advance for the answer

Greetings

J-D Gasser
Back to Top
Adrian Gallero View Drop Down
TMS Support
TMS Support
Avatar

Joined: 18 May 2010
Posts: 1174
Post Options Post Options   Quote Adrian Gallero Quote  Post ReplyReply Direct Link To This Post Posted: 29 Mar 2019 at 11:44am
Well, to be 100% honest, I wonder how to insert an image into a comment myself too :)  There is no place in the xls/xlsx file format to insert images into comments, so I imagine what you are really doing in the example you show is setting the "fill color" of the comment to be an image.

If that is the case, you can use some code like this to set the fill color of the comment:

            using (TUIImage Img = TUIImage.FromFile("imagename.png"))
            {
                using (var ImgStream = new FileStream("imagename.png", FileMode.Open))
                {
                    byte[] ImgData = new byte[ImgStream.Length];
                    ImgStream.Read(ImgData, 0, ImgData.Length);
                    var sourceRect = new TDrawingRelativeRect(0, 0, 100, 100);
                    var commentProperties = TCommentProperties.CreateStandard(5, 3, xls);
                    commentProperties.ShapeFill = new TShapeFill(
                        true,
                        new TBlipFill(
                            192, false,
                            new TBlip(TBlipCompression.None, ImgData, "", StandardMimeType.Png),
                            null, new TBlipFillStretch(sourceRect)
                            )
                        );

                    commentProperties.Anchor = new TClientAnchor(
                        commentProperties.Anchor.AnchorType,
                        commentProperties.Anchor.Row1,
                        commentProperties.Anchor.Dy1Pix(xls),
                        commentProperties.Anchor.Col1,
                        commentProperties.Anchor.Dx1Pix(xls),
                        (int)(Img.HeightInPoints * 96.0 / 72.0),
                        (int)(Img.Width * 96.0 / 72.0),
                        xls);

                    xls.SetComment(5, 3, " ", "", commentProperties);
                }
            }

I've tried it here, and it creates a comment similar to the screenshot you sent. Once again, this is *not* adding an image to a comment, but just setting the comment background to be an image, but I believe this is what you are doing in that screenshot since as far as I know, you just can't add images to comments.

A final note: Sadly because (very) old design decisions (going back literally decades ago), SetComment will just remove the comment if you set it to an empty/null string. So you can't add a comment which is completely empty, and for this example, I just add a space (" ") as the comment.
Back to Top
Sandoz Jean-Luc View Drop Down
New Member
New Member
Avatar

Joined: 08 Apr 2014
Posts: 6
Post Options Post Options   Quote Sandoz Jean-Luc Quote  Post ReplyReply Direct Link To This Post Posted: 01 Apr 2019 at 9:28am
Hello Adrian,
That is EXACTLY what I wanted to do, thank you for the very accurate answer.

You are right : this is not exactly adding an image to a comment, but setting an image as background.

Greetings

J-D Gasser
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down