我正在根据此Link创建designsurface
。
我需要将文档打印到打印机。我使用以下代码。一切都印刷得很好。
private void pdPrintDocument_PrintPage(object sender, PrintPageEventArgs e)
{
SizeF sz = e.Graphics.VisibleClipBounds.Size;
e.Graphics.TranslateTransform(sz.Width, sz.Height);
e.Graphics.RotateTransform(180);
//draw sample string
e.Graphics.DrawString("Hello", new Font(FontFamily.GenericSerif, 12, FontStyle.Bold, GraphicsUnit.Pixel), Brushes.Blue, new RectangleF(50, 50, 100, 75), new StringFormat());
//draw the objects from designsurface
designSurfaceCtrl.DrawingObjects.PrintObjects(e.Graphics);
e.Graphics.RotateTransform(-180);
e.HasMorePages = false;
designSurfaceCtrl.Invalidate();
}
但是当试图将整个文档旋转到180时,只打印文本Hello。
在PrintObjects
方法中调用的其他对象不打印。
其他方法:
public void PrintObjects(Graphics g)
{
g.PageUnit = GraphicsUnit.Pixel;
if (InnerList.Count > 0)
{
int i;
ArrayList jk = new ArrayList();
for (i = 0; i <= InnerList.Count - 1; i++)
{
jk.Add(InnerList[i]);
}
for (i = 0; i <= jk.Count - 1; i++)
{
var drawObj = (GraphicObject)jk[i];
if (drawObj.IsPrintable)
{
drawObj.Draw(g);
}
}
}
}
对象绘制覆盖:
public override void Draw(Graphics g, bool withBackground = false)
{
var gContainer = g.BeginContainer();
if (AutoSize)
{
SizeF mySize = g.MeasureString(Account1Text, MFont);
Width = Convert.ToInt32(mySize.Width);
Height = Convert.ToInt32(mySize.Height + 2);
//while printing no need to print background color
if (withBackground)
{
g.FillRectangle(new SolidBrush(MBackColor), X, Y, Width, Height);
}
g.DrawString(Account1Text, MFont, new SolidBrush(MColor), X, Y);
}
else
{
RectangleF rect1 = new RectangleF(X, Y, Width, Height + 2);
//while printing no need to print background color
if (withBackground)
{
g.FillRectangle(new SolidBrush(MBackColor), X, Y, Width, Height);
}
g.DrawString(Account1Text, MFont, new SolidBrush(MColor), rect1);
}
g.EndContainer(gContainer);
}
我应该在哪里研究?