连续印刷 [英] Continuous Printing

查看:158
本文介绍了连续印刷的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想每时每刻在打印机上打印连续的圆...但是发生的是,打印机在不同的页面上而不是在同一页上打印圆的圆弧...这些圆弧将合并形成一个完整的圆...

如果有人可以帮忙...

这是代码




命名空间TestApplication
{
公共局部类Form1:Form
{
图形g;
float stAngle = 0;
float swAngle = 10;

公共Form1()
{
InitializeComponent();
}

私有void printDocument1_PrintPage(对象发送者,System.Drawing.Printing.PrintPageEventArgs e)
{

矩形r1 =新矩形(20,20,40,40);
e.Graphics.DrawArc(Pens.Red,r1,stAngle,swAngle);
}
public void StartPrint()
{
this.printDocument1.PrintPage + =新的PrintPageEventHandler(printDocument1_PrintPage);
System.Windows.Forms.PrintDialog PrintDialog1 =新的PrintDialog();


DialogResult结果= PrintDialog1.ShowDialog();
如果(结果== DialogResult.OK)
{
printDocument1.PrintController = new StandardPrintController();
printDocument1.Print();
}
}



私有无效Form1_Paint(对象发送者,PaintEventArgs e)
{
g = panel1.CreateGraphics();

DrawObjects(g);
}

私有void DrawObjects(Graphics g)
{

矩形r1 =新矩形(20,20,40,40);

for(int i = 1; i< 20; i = i + 1)
{
g.DrawArc(Pens.Red,r1,stAngle,swAngle);
stAngle = swAngle;
swAngle = swAngle + 10;
Thread.Sleep(100);
StartPrint();
}
}

private void button2_Click(对象发送者,EventArgs e)
{
this.Paint + =新的System.Windows.Forms.PaintEventHandler(this.Form1_Paint);
}
}
}

I want to print continuous circle on the printer at every instant...but what happens is, printer prints the arcs of the circle on different pages instead on the same page...these arcs will combine to form a complete circle...

If anyone can help plz...

Here is the code




namespace TestApplication
{
public partial class Form1 : Form
{
Graphics g;
float stAngle = 0;
float swAngle = 10;

public Form1()
{
InitializeComponent();
}

private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{

Rectangle r1 = new Rectangle(20, 20, 40, 40);
e.Graphics.DrawArc(Pens.Red, r1, stAngle, swAngle);
}
public void StartPrint()
{
this.printDocument1.PrintPage += new PrintPageEventHandler(printDocument1_PrintPage);
System.Windows.Forms.PrintDialog PrintDialog1 = new PrintDialog();


DialogResult result = PrintDialog1.ShowDialog();
if (result == DialogResult.OK)
{
printDocument1.PrintController = new StandardPrintController();
printDocument1.Print();
}
}



private void Form1_Paint(object sender, PaintEventArgs e)
{
g = panel1.CreateGraphics();

DrawObjects(g);
}

private void DrawObjects(Graphics g)
{

Rectangle r1 = new Rectangle(20, 20, 40, 40);

for (int i = 1; i < 20; i=i+1)
{
g.DrawArc(Pens.Red, r1, stAngle, swAngle);
stAngle =swAngle ;
swAngle =swAngle+10 ;
Thread.Sleep(100);
StartPrint();
}
}

private void button2_Click(object sender, EventArgs e)
{
this.Paint += new System.Windows.Forms.PaintEventHandler(this.Form1_Paint);
}
}
}

推荐答案

写道:​​

g = panel1.CreateGraphics();

g = panel1.CreateGraphics();



永远不要这样做. PaintEventArgs有一个图形对象供您绘制.




Never do this. Your PaintEventArgs has a graphics object for you to draw on.


写道:​​

Thread.Sleep(100);

Thread.Sleep(100);



您到底为什么要在印刷过程中入睡?



Why on earth would you sleep in the middle of printing ?

写道:​​

e.Graphics.DrawArc(Pens.Red,r1,stAngle,swAngle);

e.Graphics.DrawArc(Pens.Red, r1, stAngle, swAngle);



您的打印代码绘制的是弧形,而不是圆形,因此您将获得所得到的结果.



Your print code draws arcs, not circles, so that is what you''re getting.


这篇关于连续印刷的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆