c# winform如何设置打印纸张大小
Graphicsg=e.Graphics;intfrmw=this.Width;intfrmh=this.Height;this.printDocument1.Defau...
Graphics g = e.Graphics;
int frmw = this.Width;
int frmh = this.Height;
this.printDocument1.DefaultPageSettings.PaperSize = new System.Drawing.Printing.PaperSize("Custom", frmw, frmh);
this.printDocument1.DefaultPageSettings.Margins = new System.Drawing.Printing.Margins(0, 0, 0, 0);
foreach (Control crl in this.Controls)
{
if (crl is TextBox)
{
int Left = crl.Location.X;
int Top = crl.Location.Y;
int width = crl.Width;
int height = crl.Height;
Font prnFont = new Font(crl.Font.Name, crl.Font.Size, crl.Font.Style);
Rectangle r = new Rectangle(Left, Top, width, height);
g.DrawRectangle(Pens.White, r);
SolidBrush prnBrush = new SolidBrush(crl.ForeColor);
g.DrawString(crl.Text, prnFont, prnBrush, r);//在长方形画字符串
} }
为何我这样设置却没有用????他还是按照默认A4的打印出来 展开
int frmw = this.Width;
int frmh = this.Height;
this.printDocument1.DefaultPageSettings.PaperSize = new System.Drawing.Printing.PaperSize("Custom", frmw, frmh);
this.printDocument1.DefaultPageSettings.Margins = new System.Drawing.Printing.Margins(0, 0, 0, 0);
foreach (Control crl in this.Controls)
{
if (crl is TextBox)
{
int Left = crl.Location.X;
int Top = crl.Location.Y;
int width = crl.Width;
int height = crl.Height;
Font prnFont = new Font(crl.Font.Name, crl.Font.Size, crl.Font.Style);
Rectangle r = new Rectangle(Left, Top, width, height);
g.DrawRectangle(Pens.White, r);
SolidBrush prnBrush = new SolidBrush(crl.ForeColor);
g.DrawString(crl.Text, prnFont, prnBrush, r);//在长方形画字符串
} }
为何我这样设置却没有用????他还是按照默认A4的打印出来 展开
2个回答
展开全部
首先你要到指定印表机下,新增加你要列印的纸张大小。
//然后在代码中,指定尺寸
foreach (PaperSize paperSize in printDocument1.PrinterSettings.PaperSizes)
{
if (paperSize.Width == frmw && paperSize.Height == frmh)
{
this.printDocument1.DefaultPageSettings.PaperSize = paperSize;
break;
}
}
这样列印出来,就是你要的纸张大小
//然后在代码中,指定尺寸
foreach (PaperSize paperSize in printDocument1.PrinterSettings.PaperSizes)
{
if (paperSize.Width == frmw && paperSize.Height == frmh)
{
this.printDocument1.DefaultPageSettings.PaperSize = paperSize;
break;
}
}
这样列印出来,就是你要的纸张大小
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询