Article | 60000976 |
Type | HowTo |
Product | Engine |
Version | 6 |
Date Added | 10/13/2009 |
Submitted by | Wayne Romer |
Keywords |
using
System;namespace WindowsApplication2
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private vdDocument doc { get { return vdFramedControl1.BaseControl.ActiveDocument; } }
VectorDraw.Render.grTextStyle textstyle = null;
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
doc.OnDrawAfter += new vdDocument.DrawAfterEventHandler(doc_OnDrawAfter);
doc.OnDrawOverAll += new vdDocument.DrawOverAllEventHandler(doc_OnDrawOverAll);
//create a global TextStyle used to draw the overall text
textstyle = new VectorDraw.Render.grTextStyle("Arial");
}
{
double DPIScale=1.0d;
//ratio render DPI/ScreenDPI
if (render.Display ==
VectorDraw.Render.vdRender.DisplayMode.PRINT_PREVIEW_PAPER
|| render.Display == VectorDraw.Render.vdRender.DisplayMode.PRINT_PREVIEW)
{
DPIScale = (double)render.Height
/ (double)(doc.ActiveLayOut.Printer.LandScape
? doc.ActiveLayOut.Printer.paperSize.Width :
doc.ActiveLayOut.Printer.paperSize.Height);
}
//make the active render unlock so it will always
draw using GDIPlus API
bool islock = render.IsLock;
if (islock) render.UnLock();
//Get the display string
string str = System.DateTime.Now.ToShortDateString();
//Calculate the text box with the selecting text
style Size.
Box textbox =
textstyle.GetBaseTextBox(str, null);
//create a box that will be drawn in the text
background and will be 25% biger tham the text box.
Box box =
new
Box(textbox);
box.AddWidth(textbox.Height * 0.25);
//calculate a Matrix that will scale and offset
the drawing primitives.
Matrix m =
new
Matrix();
double OneMM_DUSize =
render.PixelSize * DPIScale * render.DpiY * 1.0d / 25.4;
//select the text height to be 10 mm of height.
double scale = OneMM_DUSize
* 10.0d / textbox.Height;
Box rendersize =
render.ClipBounds.ToBox();
//select the left offset of the box to be 15 mm of width, and the the bottom
offset of the box to be 15 mm.
gPoint offset =
new
gPoint((render.ClipBounds.Xmin
+ OneMM_DUSize * 15.0d), (render.ClipBounds.Ymin + box.Height * scale +
OneMM_DUSize * 15.0d));
if
(render.IsPrinting) //taking into
consideration the printer hardware margins
{
offset.x += (OneMM_DUSize
* Globals.INCH_MM *
doc.ActiveLayOut.Printer.Hardmargins.Left / 100);
offset.y += (OneMM_DUSize
* Globals.INCH_MM *
doc.ActiveLayOut.Printer.Hardmargins.Bottom / 100);
}
m.ScaleMatrix(scale, scale,
scale);
m.TranslateMatrix(offset);
//select the matrix and draw the primitives
//we use the OnDrawAfter event only when priniting because the OnDrawOverAll is not fired when printing
void doc_OnDrawAfter(object sender, VectorDraw.Render.vdRender render)
{
if (render.IsPrinting && (render.Display == VectorDraw.Render.vdRender.DisplayMode.PRINT_PREVIEW_PAPER || render.Display == VectorDraw.Render.vdRender.DisplayMode.PRINT_PRINTER_PAPER)) drawoverall(render);
}
void doc_OnDrawOverAll(object sender, VectorDraw.Render.vdRender render, ref bool cancel)
{
drawoverall(render);
}
}
}