We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Is it possible to add an Image in the same way as a Label on a Connector?

The label option is very useful, but it appears to only allow text. Is there a way to add an image instead of just text to a connector? (and that is any type of connector Orthoganal, Polyline. etc).

To be honest it would be useful to be able to that to a Node as well (I have implemented this on a node using groups already, but being able to do it by adding to the Labels collection would make life easier!).

Thanks,


3 Replies

PM Pandi Murugan A Syncfusion Team January 10, 2011 05:22 AM UTC

Hi Aubyn Crawford,

Thanks for using Syncfusion products.

Connectors don't have direct support for adding image to their GraphicsPath instead of Label but it can be achievable. We suggest you to customize a connector and override its render method to achieve your requirement and we have customized the LineConnector to meet your requirement as below. Please refer the below code snippet.

[C#]
//Custom LineConnector
class MyConnector: LineConnector
{
public MyConnector(PointF ptStart, PointF ptEnd)
: base(ptStart, ptEnd)
{
this.LineStyle.LineColor = Color.Orange;
this.LineStyle.LineWidth = 2;
}
protected override void Render(Graphics gfx)
{
base.Render(gfx);
Size size = new Size(16, 16);
PointF[] pts = GetPathPoints();
Bitmap Original = new Bitmap(@"..\\..\\Or.png");
Bitmap bmp = new Bitmap(Original, size);
bmp.MakeTransparent();
Graphics g = Graphics.FromImage(bmp);
//Add image to connector
gfx.DrawImage(bmp,new Point((int)((pts[0].X+pts[1].X)/2 - 8),(int)(pts[0].Y+10)));
}
}

For your convenient, we have created a simple sample to demonstrate this and the same can be downloaded from the below link.

ConnectorWithImage-1281406032.zip

Kindly try the above sample and let me know if this helps.

Regards,
Pandi Murugan A





AC Aubyn Crawford January 12, 2011 10:43 PM UTC

Perfect! Worked first time.

Really quick response from yourselves, which makes a big difference.



PM Pandi Murugan A Syncfusion Team January 13, 2011 05:28 AM UTC

Hi Aubyn Crawford,

Thanks for the update.

We are glad to know that the issue is resolved. Please let me know if you have any other concerns and we will be happy to assist you.

Regards,
Pandi Murugan A


Loader.
Live Chat Icon For mobile
Up arrow icon