我有一个支票,我正在尝试手动打印数据 - 不允许使用报告工具 - 我的目标是PDF打印机和支票纸,我必须使用A4打印机。
以下是插图:
我的步骤是:
在第1步中,我创建了PrintDocument
个实例并设置DefaultPageSettings.PaperSize
以匹配输入纸张尺寸,方法是将RawKind
设置为120
,这意味着自定义纸张尺寸,然后我设置了PrintPage
处理程序,然后拨打Print
。
在第2步中,写入e.Graphics
的数据没有问题。
在步骤3中,当打印到PDF打印机时,结果与预期一致,并且可以复制字符串,也可以在支票图像上进行手动预览。
我打印到A4打印机时的问题 - HP Laserjet 1018 - 我将上部纸盘的标尺设置在中间位置,这样它可以保持我垂直的检查,现在当打印两个事情发生了:
如何解决打印机问题?
答案 0 :(得分:0)
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
{
float vlblControlWidth;
float vlblControlHeight;
float vlblTransformX;
float vlblTransformY;
Color controlBackColor = BackColor;
Pen labelBorderPen;
SolidBrush labelBackColorBrush;
if (_transparentBG)
{
labelBorderPen = new Pen(Color.Empty, 0);
labelBackColorBrush = new SolidBrush(Color.Empty);
}
else
{
labelBorderPen = new Pen(controlBackColor, 0);
labelBackColorBrush = new SolidBrush(controlBackColor);
}
SolidBrush labelForeColorBrush = new SolidBrush(base.ForeColor);
base.OnPaint(e);
vlblControlWidth = this.Size.Width;
vlblControlHeight = this.Size.Height;
e.Graphics.DrawRectangle(labelBorderPen, 0, 0,
vlblControlWidth, vlblControlHeight);
e.Graphics.FillRectangle(labelBackColorBrush, 0, 0,
vlblControlWidth, vlblControlHeight);
e.Graphics.TextRenderingHint = this._renderMode;
e.Graphics.SmoothingMode =
System.Drawing.Drawing2D.SmoothingMode.HighQuality;
if (this.TextDrawMode == DrawMode.BottomUp)
{
vlblTransformX = 0;
vlblTransformY = vlblControlHeight;
e.Graphics.TranslateTransform(vlblTransformX, vlblTransformY);
e.Graphics.RotateTransform(270);
e.Graphics.DrawString(labelText, Font, labelForeColorBrush, 0, 0);
}
else
{
vlblTransformX = vlblControlWidth;
vlblTransformY = vlblControlHeight;
e.Graphics.TranslateTransform(vlblControlWidth, 0);
e.Graphics.RotateTransform(90);
e.Graphics.DrawString(labelText, Font, labelForeColorBrush, 0,
0,StringFormat.GenericTypographic);
}
}
SetStyle(System.Windows.Forms.ControlStyles.Opaque, true);
}
protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.ExStyle |= 0x20; // Turn on WS_EX_TRANSPARENT
return cp;
}
}