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