Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Customizing the look and feel of links (Read 705 times)
dpru2
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 19
Joined: Feb 2nd, 2021
Customizing the look and feel of links
Dec 20th, 2022 at 9:45pm
Print Post  
I'd like to customize the look and feel of links on my diagram. Overall the default style isn't bad - at the moment I just want to customize the thickness and color of the links.

I've tried two ways of doing this. First, on my diagram object I have the following line of code:
Code (C++)
Select All
diagram.LinkBrush = new SolidBrush(Color.FromRgb(255, 0, 0));
 



This didn't have any effect on the color of the links. However, I did notice that the LinkBrush property is now obsolete, so I tried the suggested way of using a theme. This is my code for that:
Code (C++)
Select All
MindFusion.Diagramming.Theme diagram_theme = new MindFusion.Diagramming.Theme();
MindFusion.Diagramming.DiagramLinkStyle diagram_link_style = new MindFusion.Diagramming.DiagramLinkStyle();
diagram_link_style.Stroke = new SolidBrush(Color.FromRgb(255, 0, 0));
diagram_link_style.StrokeThickness = 1;
diagram_theme.RegisterStyle(typeof(MindFusion.Diagramming.DiagramLink), diagram_link_style);
diagram.Theme = diagram_theme;
 



This also didn't seem to have any effect on the links in my diagram. Currently the default color of the links is a dark green color (as seen in the attached image).

For now this is all I am trying to accomplish, however, in the future I'd actually like to have custom link styles based upon the nodes that the link is connected to. I assume that in order to do this, I'll likely need to set the CustomDraw property of the diagram? Or handle the DrawLink event?
  

diagram_links.png ( 6 KB | 55 Downloads )
diagram_links.png
Back to top
 
IP Logged
 
dpru2
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 19
Joined: Feb 2nd, 2021
Re: Customizing the look and feel of links
Reply #1 - Dec 20th, 2022 at 11:05pm
Print Post  
So, here's an update:

I went ahead and decided to handle all drawing of links, so I implemented this code:
Code (C++)
Select All
this.LinkCustomDraw = CustomDraw.Full;
this.DrawLink += MyDiagram_DrawLink;
 



And then I implemented the following function to draw links:
Code (C++)
Select All
private void MyDiagram_DrawLink(object sender, DrawLinkEventArgs e)
{
    Color pen_color = DeterminePenColor();
    Pen drawing_pen = new Pen(pen_color);
    drawing_pen.LineJoin = MindFusion.Drawing.LineJoin.Round;
    drawing_pen.Width = 2;
    var graphics = e.Graphics;
    graphics.DrawLines(drawing_pen, e.Points);
}
 



Overall the code is working well. The colors and line thickness are as I expect them to be. However, I was expecting the line segments to be joined with "rounded" line-endings, but as you can see in the attached image, the line-joins are not rounded. They are flat.

Any suggestions on fixing that?
  

diagram_links_02.png ( 4 KB | 54 Downloads )
diagram_links_02.png
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3154
Joined: Oct 19th, 2005
Re: Customizing the look and feel of links
Reply #2 - Dec 21st, 2022 at 12:23pm
Print Post  
DiagramLink.Brush initialized from LinkBrush is used to fill arrowheads. Try setting LinkPen or DiagramLink.Pen instead. Make sure link's Brush / Pen are null in order to query values from styles or themes.

We'll check joints in DrawLines for next release. For time being try if DrawPath works better.

Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3154
Joined: Oct 19th, 2005
Re: Customizing the look and feel of links
Reply #3 - Jan 2nd, 2023 at 6:05am
Print Post  
New build here should fix line joints:
https://www.nuget.org/packages/MindFusion.Diagramming.Maui/

Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint