Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C# (http://www.go4expert.com/forums/c-sharp/)
-   -   need help with invterval printing (http://www.go4expert.com/forums/help-invterval-printing-t587/)

markyjj 12Feb2006 01:22

need help with invterval printing
 
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

shabbir 12Feb2006 09:13

Re: need help with invterval printing
 
I have copied your code and used the syntax highlighter so that the C# expert can better understand the code. You can also do the same using the bbcode
Code: csharp

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();
 }
}


coderzone 12Feb2006 09:19

Re: need help with invterval printing
 
It looks like you are declaring a class MainClass and inside the static member function main trying to initilization and create the object of the same class.


All times are GMT +5.5. The time now is 16:07.