Hello,
I have used the event DrawNode on a MindFusion.Diagramming.Diagram.
the code is similar to this:
protected void flowChart_DrawNode(object sender, DrawNodeEventArgs e)
{
var node = e.Node.Tag as DiagramNode;
if (node != null)
node.DrawNode(e);
}
and the Node (which has a MindFusion.Diagramming.ShapeNode as a private field) has this DrawNode method
public override void DrawNode(DrawNodeEventArgs e)
{
System.IntPtr gHdc = e.Graphics.GetHdc();
// Get the node bounds
var bounds = diagramPanel.DiagramView.DocToClient(new RectangleF(ShapeNode.Bounds.X, ShapeNode.Bounds.Y, ShapeNode.Bounds.Width, ShapeNode.Bounds.Height));
bounds = new Rectangle(bounds.X - 3, bounds.Y - 3, bounds.Width + 7, bounds.Height + 7);
System.Drawing.SolidBrush brush = new System.Drawing.SolidBrush(((MindFusion.Drawing.SolidBrush)ShapeNode.Brush).Color);
System.Drawing.Pen pen = new System.Drawing.Pen(((MindFusion.Drawing.Pen)ShapeNode.Pen).Color, ((MindFusion.Drawing.Pen)ShapeNode.Pen).Width);
pen.DashStyle = ((MindFusion.Drawing.Pen)ShapeNode.Pen).DashStyle;
try
{
using (var g = Graphics.FromHdc(gHdc))
{
// Draw the background color
g.FillRectangle(brush, bounds);
g.DrawRectangle(pen, rectangleBounds);
// Render the RTF contents...
rtfControl.Render(g, bounds);
}
}
finally
{
e.Graphics.ReleaseHdc(gHdc);
}
}
And the rtfControl Render method
public void Render(Graphics g, Rectangle rc)
{
// convert rect from pixels to twips
rc.X = (int)(rc.X * 1440 / g.DpiX);
rc.Y = (int)(rc.Y * 1440 / g.DpiY);
rc.Width = rc.X + (int)((rc.Width) * 1440 / g.DpiX);
rc.Height = rc.Y + (int)((rc.Height) * 1440 / g.DpiY);
// get dc
IntPtr hdc = g.GetHdc();
// set up FORMATRANGE struct
FORMATRANGE fmt = new FORMATRANGE();
fmt.hdc = fmt.hdcTarget = hdc;
fmt.rc = fmt.rcPage = rc;
fmt.cpMin = 0;
fmt.cpMax = -1;
// render RTF
int render = 1;
SendMessageFormatRange(Handle, EM_FORMATRANGE, render, ref fmt);
// clean up
SendMessage(Handle, EM_FORMATRANGE, render, 0);
// done with dc
g.ReleaseHdc(hdc);
}
// FORMATRANGE is used by RichEd20.dll to render RTF
/// <summary>
///
/// </summary>
internal struct FORMATRANGE
{
internal IntPtr hdc, hdcTarget;
internal Rectangle rc, rcPage;
internal int cpMin, cpMax;
}
The problem is that this code works fine when drawing the mindfusion diagram within a WinForms application control, but when using the diagramView.PrintPreviewEx(printDocument); method, the node is not well drawn on the final page of the print preview dialog, seems to be more little and in the left sqare position, and I know that one reason is the print resolution for the graphics object which is 600 dpi when using the e.Graphics object for printing while when drawing the node on the windows application uses 96 dpi, but I don't know why is not working properly when getting the bounds of the shape.
Attached is the ShapeNode in the right place using the diagram within the windows forms cotrol, and whe previewing
Any help would be appreciated
Thanks in advance