Hi Stoyan,
I've got 3 questions about the differences between MindFusion for WPF and WinForms.
Question 1:
In WPF I can override the Draw method of a custome-made node with the following code:
public override void Draw(DrawingContext graphics, MindFusion.Diagramming.Wpf.RenderOptions options)
{
double totalHeight = Bounds.Height;
double padding = 20;
double ifHeight = Then_connected_node != null ? Then_connected_node.Bounds.Height : 0;
double elseHeight = Else_connected_node != null ? Else_connected_node.Bounds.Height : 0;
// Then-part and Else-part are null
if (ifHeight == 0 && elseHeight == 0)
{
ifHeight = elseHeight = (totalHeight - 3 * padding) / 2;
}
// Only Then-part is null
else if (ifHeight == 0)
{
ifHeight = totalHeight - elseHeight - 3 * padding;
}
// Only Else-part is null
else if (elseHeight == 0)
{
elseHeight = totalHeight - ifHeight - 3 * padding;
}
var shape = new PathGeometry();
shape.Figures.Add(new PathFigure(new Point(), new[]
{
new LineSegment(new Point(5, 0), true),
new LineSegment(new Point(10, -7), true),
new LineSegment(new Point(15, 0), true),
new LineSegment(new Point(Bounds.Width, 0), true),
new LineSegment(new Point(Bounds.Width, padding), true),
new LineSegment(new Point(35, padding), true),
new LineSegment(new Point(30, padding-7), true),
new LineSegment(new Point(25, padding), true),
new LineSegment(new Point(padding, padding), true),
new LineSegment(new Point(padding, padding + ifHeight), true),
new LineSegment(new Point(Bounds.Width, padding + ifHeight), true),
new LineSegment(new Point(Bounds.Width, Bounds.Height - padding - elseHeight), true),
new LineSegment(new Point(35, Bounds.Height - padding - elseHeight), true),
new LineSegment(new Point(30, Bounds.Height - padding - elseHeight - 7), true),
new LineSegment(new Point(25, Bounds.Height - padding - elseHeight), true),
new LineSegment(new Point(padding, Bounds.Height - padding - elseHeight), true),
new LineSegment(new Point(padding, Bounds.Height - padding), true),
new LineSegment(new Point(Bounds.Width, Bounds.Height - padding), true),
new LineSegment(new Point(Bounds.Width, Bounds.Height), true),
new LineSegment(new Point(15, Bounds.Height), true),
new LineSegment(new Point(10, Bounds.Height-7), true),
new LineSegment(new Point(5, Bounds.Height), true),
new LineSegment(new Point(0, Bounds.Height), true),
new LineSegment(new Point(0, 0), true),
}, true));
graphics.DrawGeometry(Brush, new Pen(Stroke, StrokeThickness), shape);
}
Is it possible to achieve the exact same in WinForms? I tried to paste the same code in a WinForms project but it doesn't seem to recognize the PathGeometry class.
Question 2:
In WPF there is a property in the Diagram class called ModificationEffect. If I set this property to ModificationEffect.MoveShades I would get a preview when moving a node in the diagram. Is there a similar property in WinForms?
Question 3:
With the code below I can drag and drop Nodes to a Diagramfield from a NodeListView and while I do this I get a preview under my cursor. Is this possible with WinForms as well ?
private DiagramNode dragIndicator = null;
public InteractionState dragInteraction = null;
// The three functions OnDiagramDragEnter, OnDiagramDragOver, OnNodeCreatedmethode are used
// to be able to have a dragpreview.
// This method is called when the cursor enters the corresponding window
private void OnDiagramDragEnter(object sender, DragEventArgs e)
{
// The if statement checks if dragIndicator is empty and if there is a dragNode present
if (dragIndicator == null && e.Data.GetDataPresent(typeof(DraggedNode)))
{
this.ModificationEffect = ModificationEffect.None;
// var data gets present node that is dragable
// var position gets the current position of the node that can be dragged
var data = (DraggedNode)e.Data.GetData(typeof(DraggedNode));
var position = e.GetPosition(this.DocumentPlane);
// Make a Copy of the current node, its on 'false' cause its not getting use by the clipboard
dragIndicator = (DiagramNode)data.Node.Clone(false);
dragIndicator.Move(position.X, position.Y); // Keeps track of the position
dragInteraction = new InteractionState(dragIndicator, 8, MindFusion.Diagramming.Wpf.Action.Modify);
dragInteraction.Start(position, this);
dragIndicator.Opacity = 0.5; // Changes the opacity of the node so that it looks transparent
this.Nodes.Add(dragIndicator); // Node is being added to the diagram - this = the diagram
e.Effects = DragDropEffects.Copy;
e.Handled = true;
}
}
// This method is called when the cursor moves inside the cursor moves inside the corresponding window
public void OnDiagramDragOver(object sender, DragEventArgs e)
{
// Checks whether the dragindicator is filled with the data of the node that is being dragged
if (dragIndicator != null)
{
var position = e.GetPosition(this.DocumentPlane);
dragInteraction.Update(position, this);
//dragIndicator.Move(position.X, position.Y);
e.Effects = DragDropEffects.Copy;
e.Handled = true;
}
}
// Removes the contents of the dragIndicator, so it can be use again if
private void OnNodeCreated(object sender, NodeEventArgs e)
{
if (dragIndicator != null)
{
this.ModificationEffect = ModificationEffect.MoveShades;
e.Node.Bounds = dragIndicator.Bounds;
this.Nodes.Remove(dragIndicator);
dragIndicator = null;
BR_Shape.lastInflatedNode = null;
}
}
Greets,
Vincent