Click here to Skip to main content
15,890,282 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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);
}
}
}
Posted

1 solution

wrote:
g = panel1.CreateGraphics();


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


wrote:
Thread.Sleep(100);


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

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


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

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900