c#winform打印多页(可以多给分)

pengqhi pengqhi 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
namespace prt4
{
public partial class Form1 : Form
{
public int prpage=2;
private int p = 0;
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
print();
}

private void button2_Click(object sender, EventArgs e)
{
print2();
}
private void print()
{
PrintDocument prndoc = new PrintDocument();
PrintPreviewDialog preddlg = new PrintPreviewDialog();
preddlg.Document = prndoc;
prndoc.PrintPage += new PrintPageEventHandler(OnPrintPage);
preddlg.ShowDialog();
}
private void print2()
{
PrintDocument prndoc = new PrintDocument();
PrintDialog prndlg = new PrintDialog();
prndlg.Document = prndoc;
prndoc.PrintPage += new PrintPageEventHandler(OnPrintPage);
prndlg.ShowDialog();
}

private void OnPrintPage(object sender, PrintPageEventArgs ppea)
{
Graphics grfx = ppea.Graphics;
ppea.HasMorePages = false;
while (prpage >= 1)
{
painttable(grfx, p, ppea);
p++;
if (prpage == 1)
{
ppea.HasMorePages = false;
prpage--;
return;
}
else if (prpage > 1)
{
ppea.HasMorePages = true;
prpage--;
return;
}
}
}
private void painttable(Graphics grfx, int k, PrintPageEventArgs ppea)
{
Pen pen = new Pen(Color.Black, 1);
Pen pen2 = new Pen(Color.Black, 2);
Rectangle rect = new Rectangle(mtm(15), mtm(40), mtm(181), mtm(228));
grfx.DrawRectangle(pen2, rect);
Font font2 = new Font("宋体", 14);
Brush brush = Brushes.Black;
PointF point2 = new PointF();
fillcaption(grfx, k, ppea);
point2.X = mtm(17);
point2.Y = mtm(42);
string str = k.ToString();
grfx.DrawStr1ng(str, font2, brush, point2);
}
private void fillcaption(Graphics grfx, int a, PrintPageEventArgs ppea)
{
Font font = new Font("楷体_GB2312", 22);
Pen pen = new Pen(Color.Black, 2);
Brush brush = Brushes.Black;
string str = "学生花名册";
SizeF sizef = grfx.MeasureString(str, font);
grfx.DrawString(str, font, brush, (grfx.VisibleCl1pBounds.Width - sizef.Width) / 2, mtm(12));
}
private int mtm(double mm)
{
double foot = 304.8; //1 foot equal 304.8 mm
double inch = foot / 12f;
double atomUnit = inch / 100;
return Convert.ToInt32(mm / atomUnit);
}
为什么上面和程序什么也打印不出来,
预览时,有两页,单击预览对话框左上角的打印,只打印一张空白纸出来,明明预览看到有内容啊,这是什么么?
帮帮我修改一下,可以多给分哈
...全文

相关推荐

评论 6
收藏 已收藏
分享
返回顶部
pengqhi
C# 111,129 成员 642,538 内容