0
Answer

need help with interval printing

Ask a question
mark jones

mark jones

18y
1.5k
1

Can anyone please suggest any help with the following program.  I need to create a program that prints an ellipse on the left side of the page every 5 seconds.  I have produced the follwing code but when I build the code I get the following error code, 'MainClass.pd denotes where a class was expected'.

Here is the code I have created:

using System;
using System.Timers;
using System.Drawing.Printing;
using System.Drawing;

 

class MainClass
{
 PrintDocument pd = new PrintDocument();
 private Timer timer = new Timer();
 private void MyHandler(object sender, ElapsedEventArgs args)
 { 
  
  pd.Print();  
 }
 
 private void pd_PrintPage(object sender, PrintPageEventArgs args)
 {
  
   args.Graphics.FillEllipse(Brushes.Aquamarine,
    args.MarginBounds.X,
    args.MarginBounds.Y,
    args.MarginBounds.Width / 2,
    args.MarginBounds.Height);
  
 }

 static void Main(string[] args)
 {
  
  MainClass mc = new MainClass();

  double Interval = 5000;
  
  mc.timer.Interval = Interval;
       
  mc.timer.Elapsed +=new ElapsedEventHandler(mc.MyHandler);
        pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);
  
  mc.timer.Start();

  //pause for user input
  Console.WriteLine("Press ENTER to end timer\n");
  Console.ReadLine();
 }
}

Any advice would be very helpful....thanks


Next Recommended Forum