如何让timer 停止?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace x3
{
public partial class Form1 : Form
{
public static void Main()
{
Application.Run(new Form1());
}
public Form1()
{
//InitializeComponent();
Text = "hello:";
Timer timer=new Timer() ;
timer.Interval =10;
timer.Tick +=new EventHandler (TimerOnTick);
timer.Start();
}
void TimerOnTick(object obj,EventArgs ea)
{
Random rand= new Random ();
int x1=rand.Next(ClientSize.Width +100);
int x2=rand.Next(ClientSize.Width -100);
int y1=rand.Next(ClientSize.Height-200 );
int y2=rand.Next(ClientSize.Height-200);
Color color =Color.FromArgb(rand.Next(256),
rand.Next(256),
rand.Next(256));
Graphics grfx=CreateGraphics ();
grfx.FillRectangle (new SolidBrush (color),Math .Min (x1,x2),Math.Min(y1,y2),
Math.Abs(x2-x1),Math.Abs(y2-y1));
grfx.Dispose ();
}
}
}
如何让timer timer 停止运行,