Article | 60000349 |
Type | HowTo |
Product | Engine |
Version | 6 |
Date Added | 12/14/2007 12:00:00 AM |
Fixed | (12/14/2007 12:00:00 AM) |
Submitted by | Paul Sajecki |
Summary
Using vdProControl in C# and during printing the DrawAfter Event fires multiple times with render.PrinterMode = PRINT_PRINTER
Solution
Depending on the printer and its resolution the VDF splits the paper in regions so it can print in large printers and this is because the drawing may contain big size bitmaps or when it can only be printed as a bitmap (like in 3D Render mode). The Render in VDF 6 has changed a lot from version 5 and this is why you get the problem. The code should be written different :
If you use the PRINT_PRINTER then you should draw the objects you like they are actual objects in Drawing units, like :
if (render.PrinterMode == VDrawI5.VdConstPrintMode.PRINT_PRINTER)
{
VDrawI5.vdPrint printer = vdProControl.ActiveDocument.Printer;
double[] rect = printer.PrintWindow as double[];
double[] bottomLeft = new double[] { rect[0],rect[1] };
double[] topRight = new double[] { rect[2], rect[3] };
render.Select_Pen(VDrawI5.VdConstPen.VdPenSolid, 1, 0);
render.PushMatrix();
render.SelectWorldMatrix();
render.Drawline(bottomLeft[0], bottomLeft[1], 0, topRight[0], topRight[1], 0, 0);
render.Drawline(topRight[0], bottomLeft[1], 0, bottomLeft[0], topRight[1], 0, 0);
render.Drawcircle((bottomLeft[0] + topRight[0]) / 2, (bottomLeft[1] + topRight[1]) / 2, 0, (-bottomLeft[1] + topRight[1]) / 2);
render.PopMatrix();
}
The code inside the if{} will run 4 times (or more dependinmg on the printer/paper/resolution) and only the portion of the lines/circle will be rendered in each "region" and will draw the things you like.
If you use the PRINT_PRINTER_PAPER then you should use a code like you did, the catch here is that you set the pen (color, type, width), like :
if (render.PrinterMode == VDrawI5.VdConstPrintMode.PRINT_PRINTER_PAPER)
{
Console.WriteLine(render.PrinterMode.ToString());
render.Select_Pen(VDrawI5.VdConstPen.VdPenSolid, 1, 0);
double[] bottomLeft = new double[3];
double[] topRight = new double[3];
int left = 0, top = 0, right = 0, bottom = 0;
render.GetWindowExt(ref left, ref top, ref right, ref bottom);
render.PixelToView(left, bottom, ref bottomLeft[0], ref bottomLeft[1]);
render.PixelToView(right, top, ref topRight[0], ref topRight[1]);
render.Drawline(bottomLeft[0], bottomLeft[1], 0, topRight[0], topRight[1], 0, 0);
render.Drawline(topRight[0], bottomLeft[1], 0, bottomLeft[0], topRight[1], 0, 0);
render.Drawcircle((bottomLeft[0] + topRight[0]) / 2, (bottomLeft[1] + topRight[1]) / 2, 0, (-bottomLeft[1] + topRight[1]) / 2);
}It depends on what you want to draw during printout on which method you should follow.
Also you can use the Render and DrawAfter Event of the VDF .Net libraries, like (in Form_Load) :
VectorDraw.Professional.vdObjects.vdDocument doc = vdProControl.ActiveDocument.WrapperObject as VectorDraw.Professional.vdObjects.vdDocument; doc.OnDrawAfter += new VectorDraw.Professional.vdObjects.vdDocument.DrawAfterEventHandler(doc_OnDrawAfter);and use the
void doc_OnDrawAfter(object sender, VectorDraw.Render.vdRender render) { //Do your things here }to write the code to draw the extra things in printout. In this case you will have to add in your C# project extra references like the VectorDraw.Render, VectorDraw.Geometry, VectorDraw.Serialize and VectorDraw.Generics