Hi Slavcho,
I need help me again.
Now I add myNode with CustomShape but I need to create a custom link.
I try this :
class CustomLink : DiagramLink
{
public CustomLink(Diagram parent) : base(parent)
{
MyProperty = "go there";
}
public override void Draw(MindFusion.Drawing.IGraphics graphics,RenderOptions options)
{
base.Draw(graphics, options);
}
protected override void SaveToXml(XmlElement xmlElement, XmlPersistContext context)
{
base.SaveToXml(xmlElement, context);
context.WriteString(MyProperty, "MyProperty", xmlElement);
}
protected override void LoadFromXml(XmlElement xmlElement, XmlPersistContext context)
{
base.LoadFromXml(xmlElement, context);
MyProperty = context.ReadString("MyProperty", xmlElement);
}
public string MyProperty { get; set; }
In my form :
public Form1()
{
InitializeComponent();
// non permette il disegno del link sullo stesso nodo
diagram1.AllowSelfLoops = false;
diagramView1.SmoothingMode = SmoothingMode.AntiAlias;
// disattiva in modo automatico il comportamento con il mouse della creazione del nodo e permette il disegno del solo link
//diagramView1.Behavior = Behavior.DrawLinks;
Diagram.RegisterItemClass(typeof(CustomLink), "CustomLink", 100);
diagramView1.Behavior = Behavior.Custom;
diagramView1.CustomLinkType = typeof(CustomLink);
//diagramView1.CustomNodeType = typeof(CustomShapeNode);
diagram1.ShapeHandlesStyle = HandlesStyle.Invisible;
diagram1.DynamicLinks = true;
}
This event handler to draw custom shape link:
private void diagram_DrawLink(object sender, DrawLinkEventArgs e)
{
if (e.Shadow)
{
// We are not drawing arrows shadows
return;
}
int Larghezza = 105; // larghezza del rettangolo link
PointF a = e.Points[0];
PointF b = e.Points[e.Points.Count - 1];
if (a.Equals(b))
{
// 0-length arrow, skip drawing
return;
}
int threshold = 5;
if (a.X == b.X && a.Y != b.Y)
{
threshold = 0;
}
else if (a.X != b.X && a.Y == b.Y)
{
threshold = 0;
}
PointF center = new PointF (Math.Abs(a.X - b.X)/2 + a.X + threshold, Math.Abs(a.Y -b.Y)/2+ a.Y + threshold);
e.Graphics.DrawString(e.Link.Text, new Font(new FontFamily("Arial"), 12), new System.Drawing.SolidBrush(Color.Black), center.X, center.Y);
// The fill color of the origin
Color oc =
Color.Black;
// The fill color of the destination. The destination
// can be null if the arrow is not yet created
Color dc =
Color.Black;
// In order to display a rectangle instead of a simple line,
// we need to find four points. For this purpose we
// perform the following transformations
float an = 0, r = 0;
PointF p1 = PointF.Empty;
PointF p2 = PointF.Empty;
PointF p3 = PointF.Empty;
PointF p4 = PointF.Empty;
// Find two points around the origin control point
Convert.DekartToPolar(a, b, ref an, ref r);
Convert.PolarToDekart(a, an + Larghezza, 1.2f, ref p1);
Convert.PolarToDekart(a, an - Larghezza, 1.2f, ref p2);
// At this point in 'r' we have the length of the arrow
// expressed in the current graphics unit (millimeters by default),
// and in 'an' we have the angle, between the arrow line and
// one of the coordinate axis
float length = r;
float angle = an;
// Find two points around the destination control point
Convert.DekartToPolar(b, a, ref an, ref r);
Convert.PolarToDekart(b, an + Larghezza, 1.2f, ref p3);
Convert.PolarToDekart(b, an - Larghezza, 1.2f, ref p4);
PointF[] pts = new PointF[]
{
p1, p2, p3, p4, p1
};
// Create the graphics path containing the arrow rectangle
GraphicsPath path = new GraphicsPath(FillMode.Winding);
path.AddLines(pts);
// Solid fill the arrow with white color, or the color
// of the destination box, if the arrow's type is gradient
System.Drawing.Brush solid = new System.Drawing.SolidBrush(
dc );
e.Graphics.FillPath(solid, path);
solid.Dispose();
path.Dispose();
}
My problems are :
1) In behaviours custom the mouse draws a shape and I don't want this.
2) I would like have a link in black solid rectangle without arrow and In this link I want that It is possible to write a text like the default link.
Do you know how I can do it in a simple way?
I add a image of how It should be.