1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

need help with invterval printing

Discussion in 'C#' started by markyjj, Feb 11, 2006.

  1. markyjj

    markyjj New Member

    Joined:
    Dec 7, 2005
    Messages:
    19
    Likes Received:
    0
    Trophy Points:
    0
    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
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,287
    Likes Received:
    364
    Trophy Points:
    83
    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();
     }
    }
     
  3. coderzone

    coderzone Super Moderator

    Joined:
    Jul 25, 2004
    Messages:
    734
    Likes Received:
    37
    Trophy Points:
    0
    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.
     

Share This Page