The MindFusion Forums
Flow Diagramming Components >> Windows Forms >> How to add multiple text to a node?
https://mindfusion.eu/Forum/YaBB.pl?num=1493952507

Message started by Gu Wenwei on May 5th, 2017 at 2:48am

Title: How to add multiple text to a node?
Post by Gu Wenwei on May 5th, 2017 at 2:48am
How to add multiple text to a node

Title: Re: How to add multiple text to a node?
Post by Slavcho on May 5th, 2017 at 8:29am
Use either TableNode with multiple cells or CompositeNode with multiple TextComponents. If you prefer ShapeNodes, you could set CustomDraw = Additional and draw more text by calling e.Graphics.DrawString from DrawNode event handler.

Title: Re: How to add multiple text to a node?
Post by Gu Wenwei on Oct 12th, 2017 at 5:30am
Excuse me, can you give me an example?

Title: Re: How to add multiple text to a node?
Post by Slavcho on Oct 12th, 2017 at 5:47am
For TableNodes check ClassDiagram or InteractiveTable examples. For CompositeNodes check the Scripting and Demo (EmployeeNode.cs) examples. For custom drawing example see e.g. https://mindfusion.eu/Forum/YaBB.pl?num=1355256377/3#3 , you will need to set node's CustomDraw property to get the event raised.

Regards,
Slavcho

Title: Re: How to add multiple text to a node?
Post by Gu Wenwei on Oct 15th, 2017 at 9:20am
Can Override Shape to Add multiple text?

Title: Re: How to add multiple text to a node?
Post by Slavcho on Oct 16th, 2017 at 5:33am
You can create a custom node class and override its DrawLocal method -

[code]
class ShapeNodeEx : ShapeNode
{
     public string MoreText { get; set; }

     public override void DrawLocal(IGraphics graphics, RenderOptions options)
     {
           base.DrawLocal(graphics, options);
           graphics.DrawString(MoreText, EffectiveFont, Brushes.Black, 1, 1);
     }
}[/code]

Alternatively keep an array of strings as value of Tag property, and draw them in a loop from DrawNode event handler with CusotmDraw property set.

Regards,
Slavcho

Title: Re: How to add multiple text to a node?
Post by Gu Wenwei on Dec 20th, 2017 at 2:09pm
how to Create a ShapeNodeEx?
Cannot that:
ShapeNodeEx b = diagram.Factory.CreateShapeNode(pt, new SizeF(20, 20));

Title: Re: How to add multiple text to a node?
Post by Slavcho on Dec 20th, 2017 at 4:01pm
[code]
var b = new ShapeNodeEx();
b.Bounds = new RectangleF(...);
diagram.Nodes.Add(b);[/code]

Regards,
Slavcho

Title: Re: How to add multiple text to a node?
Post by Gu Wenwei on Mar 10th, 2018 at 1:04pm
How do I put the position of SHAPE in the center?
pic_001.png ( 1 KB | 129 Downloads )

Title: Re: How to add multiple text to a node?
Post by Gu Wenwei on Mar 11th, 2018 at 3:25am
b.TextFormat.Alignment = StringAlignment.Center;
b.TextFormat.LineAlignment = StringAlignment.Center;

Title: Re: How to add multiple text to a node?
Post by Slavcho on Mar 12th, 2018 at 8:44am
Use the DrawString overload that takes a Rectangle and StringFormat arguments, passing node.GetLocalBounds() and your StringFormat as values.

Regards,
Slavcho

Title: Re: How to add multiple text to a node?
Post by Gu Wenwei on Mar 13th, 2018 at 2:51am
thx

Title: Re: How to add multiple text to a node?
Post by Gu Wenwei on Apr 22nd, 2018 at 1:30pm
how to convert diagram.Nodes to ShapeNodeEx?

Title: Re: How to add multiple text to a node?
Post by Slavcho on Apr 23rd, 2018 at 5:37am
Nodes could contain instances of multiple types. You can use the as operator to determine type while looping over the collection -

Code (]
foreach (var node in diagram.Nodes)
{
    var exNode = node as ShapeNodeEx;
    if (exNode != null)
        ...
}
[/code):



or get filtered collection using Linq's OfType extension -
[code]
var exNodes = diagram.Nodes.OfType<ShapeNodeEx>();

Title: Re: How to add multiple text to a node?
Post by Gu Wenwei on Apr 23rd, 2018 at 12:28pm
        private void LoadFCSfile(string fn)
        {
            diagramView.LoadFromFile(fn);
            bool btag = false, bp = false;
            foreach (DiagramNode node in diagram.Nodes)
            {
                if (node is ControlNode)
                {
                    btag = true;
                }
                else
                {
                    ShapeNodeEx b = node as ShapeNodeEx;
                    if (b.Shape.ToString() == "MyBlock")  //b is null, ShapeNode b, OK
                    {
                        bp = true;
                    }
                }
            }
        }

b is null
when ShapeNodeEx is ShapeNode, OK

Title: Re: How to add multiple text to a node?
Post by Slavcho on Apr 23rd, 2018 at 4:38pm
Try with  -

[code]
if (b != null && b.Shape.ToString() == "MyBlock")
[/code]

Title: Re: How to add multiple text to a node?
Post by Gu Wenwei on Apr 24th, 2018 at 3:22am
ShapeNode B = node as ShapeNode;
B not null
ShapeNodeEx B = node as ShapeNodeEx;
B is null

I want to get the data from B

Title: Re: How to add multiple text to a node?
Post by Slavcho on Apr 24th, 2018 at 6:08am
You aren't adding ShapeNodeEx-es to diagram.Nodes then, if building diagrams from code. If you are letting users draw interactively, set DiagramView.Behavior = Custom and CustomNodeType = typeof(ShapeNodeEx) to get ShapeNodeEx instances.

Title: Re: How to add multiple text to a node?
Post by Gu Wenwei on Apr 25th, 2018 at 1:46am
how to save and open?

Title: Re: How to add multiple text to a node?
Post by Slavcho on Apr 25th, 2018 at 7:25am
Call RegisterItemClass() to register your custom type for serialization. Implement either SaveTo / LoadFrom methods for binary serialization or SaveToXml / LoadFromXml ones for XML one. E.g. see these topics -

https://mindfusion.eu/Forum/YaBB.pl?num=1203351980/0#0
https://mindfusion.eu/Forum/YaBB.pl?num=1336836718/3#3

Title: Re: How to add multiple text to a node?
Post by Gu Wenwei on Apr 25th, 2018 at 1:10pm

Code (c++):
        public MainForm()
           {
                 InitializeComponent();

            Diagram.RegisterItemClass(typeof(ShapeNodeEx), "ShapeNodeEx", 1);
......
}

        class ShapeNodeEx : ShapeNode
        {
            public ShapeNodeEx(ShapeNode prototype) : base(prototype)
            {
            }
            public ShapeNodeEx()
            {
            }

            public string MoreText { get; set; }

            public override void DrawLocal(Drawing.IGraphics graphics, RenderOptions options)
            {
                base.DrawLocal(graphics, options);

                StringFormat drawFormat = new StringFormat();
                graphics.DrawString(MoreText, new Font("Yahei", 7), Brushes.DarkBlue , (float)(Bounds.Width * .5), (float)(Bounds.Height*.85), drawFormat);
            }

            protected override void SaveTo(System.IO.BinaryWriter writer, PersistContext ctx)
            {
                base.SaveTo(writer, ctx);
            }

            protected override void LoadFrom(System.IO.BinaryReader reader, PersistContext ctx)
            {
                base.LoadFrom(reader, ctx);
            }

        }


But the data is disorganized after loading

Title: Re: How to add multiple text to a node?
Post by Slavcho on Apr 25th, 2018 at 3:55pm
You must save and load your property values from respective methods implementations -

[code]
protected override void SaveTo(System.IO.BinaryWriter writer, PersistContext ctx)
{
     base.SaveTo(writer, ctx);
     writer.Write(MoreText);
}

protected override void LoadFrom(System.IO.BinaryReader reader, PersistContext ctx)
{
     base.LoadFrom(reader, ctx);
     MoreText = reader.ReadString();
}[/code]

Title: Re: How to add multiple text to a node?
Post by Gu Wenwei on Apr 29th, 2018 at 7:40am
Perfect,
Thx

The MindFusion Forums » Powered by YaBB 2.6.11!
YaBB Forum Software © 2000-2024. All Rights Reserved.