Thread: c# timer

    #1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2002
    Posts
    4
    Rep Power
    0

    c# timer


    i dragged a timer control onto the form. The timer is te to enabled. It is a webfrom. What function does the job at intervals?:is the timer1_Elapsed one. However, it does not do its job.
  2. #2
  3. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    6
    Rep Power
    0
    Timer timer = new Timer()
    timer.Interval = 1000; // Once a second
    timer.Tick += new EventHandler(OnTick);
    timer.Enabled = true;
    timer.Start();

    protected void OnTick(object s, EventArgs ea)
    {
    MessageBox.Show("Tick Interval");
    }
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2002
    Posts
    4
    Rep Power
    0
    Timers.Timer does not contain a definition for tick in c#.
    MessageBox is not in c#
  6. #4
  7. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    6
    Rep Power
    0
    ?!?!?!?!
    MessageBox IS in C#, its the most common thing.
    Timer.Timer isn't what I wrote anyway, paste that exact code into your project and it will work.

    using System;
    using System.Drawing;
    using System.Collections;
    using System.ComponentModel;
    using System.Windows.Forms;
    using System.Data;

    namespace Text_Alignment
    {
    public class Form1 : System.Windows.Forms.Form
    {
    #region General
    private System.ComponentModel.Container components = null;
    public Form1(){InitializeComponent();}
    protected override void Dispose( bool disposing )
    {
    if( disposing )
    {
    if (components != null)
    {
    components.Dispose();
    }
    }
    base.Dispose( disposing );
    }
    #endregion
    #region Windows Form Designer generated code
    private void InitializeComponent()
    {
    this.components = new System.ComponentModel.Container();
    this.Size = new System.Drawing.Size(200,200);
    this.Text = "Timer Rectangles";
    ResizeRedraw = true;

    Timer timer = new Timer();
    timer.Tick += new EventHandler(OnTick);
    timer.Interval = 1;
    timer.Start();
    }
    #endregion
    static void Main() {Application.Run(new Form1());}

    void OnTick(object sender, EventArgs ea)
    {
    Random rand = new Random();
    int x1 = rand.Next(ClientSize.Width);
    int x2 = rand.Next(ClientSize.Width);
    int y1 = rand.Next(ClientSize.Height);
    int y2 = rand.Next(ClientSize.Height);
    Color c = Color.FromArgb(rand.Next(256), rand.Next(256), rand.Next(256));

    Graphics g = CreateGraphics();

    g.FillRectangle(new SolidBrush(c), Math.Min(x1, x2), Math.Min(y1, y2), Math.Abs(x2-x1), Math.Abs(y2-y1));
    g.Dispose();
    }
    }
    }
  8. #5
  9. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2002
    Posts
    4
    Rep Power
    0

    webform, not windows


    I have a webform, take note, not a windows form. Tick and MessageBox are not webform functions
  10. #6
  11. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    6
    Rep Power
    0
    well it isn't exactly hard to convert is it?, just look up equivilants to event handlers, thats all .Tick is, and you don't need a messagebox.

IMN logo majestic logo threadwatch logo seochat tools logo