Yes i've added a call to RegisterItemClass() in the winform constructor.
hmm ... i added a no-arg constructor but no changes...
Do i have to create one item class for each custom node in my xml document or the iconNode class work for all customs nodes .
I'll give you my method; could you tell me if you see a problem please ?
My xml document :
<?xml version="1.0" encoding="utf-8" ?>
<body>
<ass8f>
<ass4f-1>
</ass4f-1>
..............
<ass4f-2>
</ass4f-2>
<ass8f>
<body>
my form constructor :
Diagram.RegisterItemClass(typeof(EspaceDeNomsBDB.Classes_Outils.IconNode), "IconNode", 1);
my icon node class :
class IconNode : DiagramNode
{
static Image defaultIcon = Bitmap.FromFile("C:\\BDB\\images\\conforme.bmp");
Image icon ;
string label ;
StringFormat format ;
static IconNode()
{
defaultIcon = new Bitmap(48, 48);
Graphics graphics = Graphics.FromImage(defaultIcon);
Font font = new Font("Arial", 48, FontStyle.Bold, GraphicsUnit.Pixel);
graphics.FillRectangle(Brushes.Transparent, 0, 0, 48, 48);
graphics.DrawString("?", font, Brushes.Black, 0, 0);
font.Dispose();
graphics.Dispose();
}
public IconNode()
{
}
public IconNode(Diagram diagram): base(diagram)
{
icon = defaultIcon;
label = "Composant";
format = new StringFormat();
format.Alignment = StringAlignment.Center;
format.LineAlignment = StringAlignment.Center;
Bounds = new RectangleF(Bounds.Location,CalculateSize());
}
public override void Draw(IGraphics graphics, RenderOptions options)
{
Rectangle iconSizePixels = new Rectangle(
0, 0, icon.Width, icon.Height);
RectangleF imageSize = MindFusion.Utilities.DeviceToDoc(
graphics, iconSizePixels);
// Draw the icon at the top-middle
graphics.DrawImage(icon,
Bounds.X + Bounds.Width / 2 - imageSize.Width / 2, Bounds.Y);
// Draw the label at the bottom
RectangleF labelBounds = RectangleF.FromLTRB(
Bounds.X, Bounds.Y + imageSize.Height,
Bounds.Right, Bounds.Bottom);
graphics.DrawString(label,
Font, Brushes.Black, labelBounds, format);
}
public override void DrawShadow(IGraphics graphics, RenderOptions options)
{
}
public Image Icon
{
get { return icon; }
set
{
icon = value;
Bounds = new RectangleF(Bounds.Location, CalculateSize());
}
}
private SizeF CalculateSize()
{
SizeF aaa = new SizeF(defaultIcon.Width, defaultIcon.Height);
return aaa;
}
public string Label
{
get { return label; }
set
{
label = value;
Bounds = new RectangleF(Bounds.Location, CalculateSize());
}
}
protected override void SaveTo(System.IO.BinaryWriter writer, PersistContext ctx)
{
base.SaveTo(writer, ctx);
// Save the label using the standard .NET BinaryWriter
writer.Write(label);
// Save the image using the MindFusion.Diagramming built-in image saving code,
// which stores the contents of shared images only once.
ctx.SaveImage(icon);
}
protected override void LoadFrom(System.IO.BinaryReader reader, PersistContext ctx)
{
base.LoadFrom(reader, ctx);
label = reader.ReadString();
icon = ctx.LoadImage();
}
my method that load the xml file :
private void button1_Click(object sender, EventArgs e)
{
string path = "C:\\BDB\\exploitation\\view.xml";
diag_view.LoadFromXml(path);
}
Is there any problem here ?
Please note that all the titles of nodes are serial numbers except the body. Do you think it can work ? because if i understood correctly i have to do a call to RegisterItemClass() in the form constructor but at that moment the program doesn't know the serial numbers that will be called so it doesn't know the title.