Custon image for component on canvas

Hi everyone,

Is there a way to display an image on a component (when this component is on canvas)?

This is what I have now:

protected override void Layout()
            Pivot = GH_Convert.ToPoint(Pivot);

            m_innerBounds = new RectangleF(Pivot.X, Pivot.Y, 100, 100);
            LayoutInputParams(Owner, m_innerBounds);
            LayoutOutputParams(Owner, m_innerBounds);
            Bounds = LayoutBounds(Owner, m_innerBounds);  


I’d like to replace the black box with an image and put XXX above or below the image.
Thank you.

Yes, but you’ll have to override the Render() method as well. When the channel is set to GH_CanvasChannel.Objects you’ll call the base class to draw the capsule, and then you can choose to draw an overlay.

Thank you David, I managed to make it work.


Here’s the code if anyone else will find it usefull:

protected override void Render(GH_Canvas canvas, Graphics graphics, GH_CanvasChannel channel)
            GH_Capsule capsule = GH_Capsule.CreateCapsule(Bounds, GH_Palette.Normal, 100, 0);
            capsule.Render(graphics, Selected, Owner.Locked, true);
            capsule = null;

            StringFormat format = new StringFormat();
            format.Alignment = StringAlignment.Center;
            format.LineAlignment = StringAlignment.Center;

            RectangleF textRectangle = Bounds;
            textRectangle.Height = 50;

            graphics.DrawString(Owner.NickName, GH_FontServer.Large, Brushes.Black, textRectangle, format);
            graphics.DrawImage(Icons.testBig, m_innerBounds.X + 27, m_innerBounds.Y + 30, 100, 100);